Practical Lesson on Climate Data Analysis 2¶

Matteo Mastropierro and Davide Zanchettin¶

  • see xarray tutorial repo at: https://github.com/xarray-contrib/xarray-tutorial.git
In [2]:
from google.colab import drive
drive.mount('/content/drive')

Model - Observation BIAS¶

The CMCC-ESM2 model we are working with at is NOT a perfect representation of reality, because of the inherent missing physical representation of some processes. What we want to examine here is the deviation this model has from the (quasi-) observations of ERA5 reanalysis.

In [5]:
%%capture

%pip install cftime
%pip install cartopy

import cftime
import cartopy.crs as ccrs
import math

import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
import cartopy.crs as ccrs
import cftime
import warnings
warnings.filterwarnings('ignore')

#%matplotlib inline
#%config InlineBackend.figure_format='retina'

Load the historical ESM simulation

In [6]:
path = '/content/drive/MyDrive/Climate Data Analysis Lesson/'
file = 'tas_Amon_CMCC-ESM2_historical_r1i1p1f1_gn_185001-201412.nc'
ds_hist = xr.load_dataset(path+file)
ds_hist
Out[6]:
<xarray.Dataset> Size: 438MB
Dimensions:    (time: 1980, bnds: 2, lat: 192, lon: 288)
Coordinates:
  * time       (time) object 16kB 1850-01-16 12:00:00 ... 2014-12-16 12:00:00
  * lat        (lat) float64 2kB -90.0 -89.06 -88.12 -87.17 ... 88.12 89.06 90.0
  * lon        (lon) float64 2kB 0.0 1.25 2.5 3.75 ... 355.0 356.2 357.5 358.8
    height     float64 8B 2.0
Dimensions without coordinates: bnds
Data variables:
    time_bnds  (time, bnds) object 32kB 1850-01-01 00:00:00 ... 2015-01-01 00...
    lat_bnds   (lat, bnds) float64 3kB -90.0 -89.53 -89.53 ... 89.53 89.53 90.0
    lon_bnds   (lon, bnds) float64 5kB -0.625 0.625 0.625 ... 358.1 358.1 359.4
    tas        (time, lat, lon) float32 438MB 250.6 251.8 250.5 ... 260.5 260.5
Attributes: (12/48)
    Conventions:            CF-1.7 CMIP-6.2
    activity_id:            CMIP
    branch_method:          standard
    branch_time_in_child:   0.0
    branch_time_in_parent:  0.0
    comment:                none
    ...                     ...
    title:                  CMCC-ESM2 output prepared for CMIP6
    variable_id:            tas
    variant_label:          r1i1p1f1
    license:                CMIP6 model data produced by CMCC is licensed und...
    cmor_version:           3.6.0
    tracking_id:            hdl:21.14100/db148e8f-76e1-424c-92e0-8f5abb588c13
xarray.Dataset
    • time: 1980
    • bnds: 2
    • lat: 192
    • lon: 288
    • time
      (time)
      object
      1850-01-16 12:00:00 ... 2014-12-...
      bounds :
      time_bnds
      axis :
      T
      long_name :
      time
      standard_name :
      time
      array([cftime.DatetimeNoLeap(1850, 1, 16, 12, 0, 0, 0, has_year_zero=True),
             cftime.DatetimeNoLeap(1850, 2, 15, 0, 0, 0, 0, has_year_zero=True),
             cftime.DatetimeNoLeap(1850, 3, 16, 12, 0, 0, 0, has_year_zero=True),
             ...,
             cftime.DatetimeNoLeap(2014, 10, 16, 12, 0, 0, 0, has_year_zero=True),
             cftime.DatetimeNoLeap(2014, 11, 16, 0, 0, 0, 0, has_year_zero=True),
             cftime.DatetimeNoLeap(2014, 12, 16, 12, 0, 0, 0, has_year_zero=True)],
            dtype=object)
    • lat
      (lat)
      float64
      -90.0 -89.06 -88.12 ... 89.06 90.0
      bounds :
      lat_bnds
      units :
      degrees_north
      axis :
      Y
      long_name :
      Latitude
      standard_name :
      latitude
      array([-90.      , -89.057592, -88.115183, -87.172775, -86.230366, -85.287958,
             -84.34555 , -83.403141, -82.460733, -81.518325, -80.575916, -79.633508,
             -78.691099, -77.748691, -76.806283, -75.863874, -74.921466, -73.979058,
             -73.036649, -72.094241, -71.151832, -70.209424, -69.267016, -68.324607,
             -67.382199, -66.439791, -65.497382, -64.554974, -63.612565, -62.670157,
             -61.727749, -60.78534 , -59.842932, -58.900524, -57.958115, -57.015707,
             -56.073298, -55.13089 , -54.188482, -53.246073, -52.303665, -51.361257,
             -50.418848, -49.47644 , -48.534031, -47.591623, -46.649215, -45.706806,
             -44.764398, -43.82199 , -42.879581, -41.937173, -40.994764, -40.052356,
             -39.109948, -38.167539, -37.225131, -36.282723, -35.340314, -34.397906,
             -33.455497, -32.513089, -31.570681, -30.628272, -29.685864, -28.743455,
             -27.801047, -26.858639, -25.91623 , -24.973822, -24.031414, -23.089005,
             -22.146597, -21.204188, -20.26178 , -19.319372, -18.376963, -17.434555,
             -16.492147, -15.549738, -14.60733 , -13.664921, -12.722513, -11.780105,
             -10.837696,  -9.895288,  -8.95288 ,  -8.010471,  -7.068063,  -6.125654,
              -5.183246,  -4.240838,  -3.298429,  -2.356021,  -1.413613,  -0.471204,
               0.471204,   1.413613,   2.356021,   3.298429,   4.240838,   5.183246,
               6.125654,   7.068063,   8.010471,   8.95288 ,   9.895288,  10.837696,
              11.780105,  12.722513,  13.664921,  14.60733 ,  15.549738,  16.492147,
              17.434555,  18.376963,  19.319372,  20.26178 ,  21.204188,  22.146597,
              23.089005,  24.031414,  24.973822,  25.91623 ,  26.858639,  27.801047,
              28.743455,  29.685864,  30.628272,  31.570681,  32.513089,  33.455497,
              34.397906,  35.340314,  36.282723,  37.225131,  38.167539,  39.109948,
              40.052356,  40.994764,  41.937173,  42.879581,  43.82199 ,  44.764398,
              45.706806,  46.649215,  47.591623,  48.534031,  49.47644 ,  50.418848,
              51.361257,  52.303665,  53.246073,  54.188482,  55.13089 ,  56.073298,
              57.015707,  57.958115,  58.900524,  59.842932,  60.78534 ,  61.727749,
              62.670157,  63.612565,  64.554974,  65.497382,  66.439791,  67.382199,
              68.324607,  69.267016,  70.209424,  71.151832,  72.094241,  73.036649,
              73.979058,  74.921466,  75.863874,  76.806283,  77.748691,  78.691099,
              79.633508,  80.575916,  81.518325,  82.460733,  83.403141,  84.34555 ,
              85.287958,  86.230366,  87.172775,  88.115183,  89.057592,  90.      ])
    • lon
      (lon)
      float64
      0.0 1.25 2.5 ... 356.2 357.5 358.8
      bounds :
      lon_bnds
      units :
      degrees_east
      axis :
      X
      long_name :
      Longitude
      standard_name :
      longitude
      array([  0.  ,   1.25,   2.5 , ..., 356.25, 357.5 , 358.75])
    • height
      ()
      float64
      2.0
      units :
      m
      axis :
      Z
      positive :
      up
      long_name :
      height
      standard_name :
      height
      array(2.)
    • time_bnds
      (time, bnds)
      object
      1850-01-01 00:00:00 ... 2015-01-...
      array([[cftime.DatetimeNoLeap(1850, 1, 1, 0, 0, 0, 0, has_year_zero=True),
              cftime.DatetimeNoLeap(1850, 2, 1, 0, 0, 0, 0, has_year_zero=True)],
             [cftime.DatetimeNoLeap(1850, 2, 1, 0, 0, 0, 0, has_year_zero=True),
              cftime.DatetimeNoLeap(1850, 3, 1, 0, 0, 0, 0, has_year_zero=True)],
             [cftime.DatetimeNoLeap(1850, 3, 1, 0, 0, 0, 0, has_year_zero=True),
              cftime.DatetimeNoLeap(1850, 4, 1, 0, 0, 0, 0, has_year_zero=True)],
             ...,
             [cftime.DatetimeNoLeap(2014, 10, 1, 0, 0, 0, 0, has_year_zero=True),
              cftime.DatetimeNoLeap(2014, 11, 1, 0, 0, 0, 0, has_year_zero=True)],
             [cftime.DatetimeNoLeap(2014, 11, 1, 0, 0, 0, 0, has_year_zero=True),
              cftime.DatetimeNoLeap(2014, 12, 1, 0, 0, 0, 0, has_year_zero=True)],
             [cftime.DatetimeNoLeap(2014, 12, 1, 0, 0, 0, 0, has_year_zero=True),
              cftime.DatetimeNoLeap(2015, 1, 1, 0, 0, 0, 0, has_year_zero=True)]],
            dtype=object)
    • lat_bnds
      (lat, bnds)
      float64
      -90.0 -89.53 -89.53 ... 89.53 90.0
      array([[-90.        , -89.52879581],
             [-89.52879581, -88.58638743],
             [-88.58638743, -87.64397906],
             [-87.64397906, -86.70157068],
             [-86.70157068, -85.7591623 ],
             [-85.7591623 , -84.81675393],
             [-84.81675393, -83.87434555],
             [-83.87434555, -82.93193717],
             [-82.93193717, -81.9895288 ],
             [-81.9895288 , -81.04712042],
             [-81.04712042, -80.10471204],
             [-80.10471204, -79.16230366],
             [-79.16230366, -78.21989529],
             [-78.21989529, -77.27748691],
             [-77.27748691, -76.33507853],
             [-76.33507853, -75.39267016],
             [-75.39267016, -74.45026178],
             [-74.45026178, -73.5078534 ],
             [-73.5078534 , -72.56544503],
             [-72.56544503, -71.62303665],
      ...
             [ 71.62303665,  72.56544503],
             [ 72.56544503,  73.5078534 ],
             [ 73.5078534 ,  74.45026178],
             [ 74.45026178,  75.39267016],
             [ 75.39267016,  76.33507853],
             [ 76.33507853,  77.27748691],
             [ 77.27748691,  78.21989529],
             [ 78.21989529,  79.16230366],
             [ 79.16230366,  80.10471204],
             [ 80.10471204,  81.04712042],
             [ 81.04712042,  81.9895288 ],
             [ 81.9895288 ,  82.93193717],
             [ 82.93193717,  83.87434555],
             [ 83.87434555,  84.81675393],
             [ 84.81675393,  85.7591623 ],
             [ 85.7591623 ,  86.70157068],
             [ 86.70157068,  87.64397906],
             [ 87.64397906,  88.58638743],
             [ 88.58638743,  89.52879581],
             [ 89.52879581,  90.        ]])
    • lon_bnds
      (lon, bnds)
      float64
      -0.625 0.625 0.625 ... 358.1 359.4
      array([[ -0.625,   0.625],
             [  0.625,   1.875],
             [  1.875,   3.125],
             [  3.125,   4.375],
             [  4.375,   5.625],
             [  5.625,   6.875],
             [  6.875,   8.125],
             [  8.125,   9.375],
             [  9.375,  10.625],
             [ 10.625,  11.875],
             [ 11.875,  13.125],
             [ 13.125,  14.375],
             [ 14.375,  15.625],
             [ 15.625,  16.875],
             [ 16.875,  18.125],
             [ 18.125,  19.375],
             [ 19.375,  20.625],
             [ 20.625,  21.875],
             [ 21.875,  23.125],
             [ 23.125,  24.375],
      ...
             [334.375, 335.625],
             [335.625, 336.875],
             [336.875, 338.125],
             [338.125, 339.375],
             [339.375, 340.625],
             [340.625, 341.875],
             [341.875, 343.125],
             [343.125, 344.375],
             [344.375, 345.625],
             [345.625, 346.875],
             [346.875, 348.125],
             [348.125, 349.375],
             [349.375, 350.625],
             [350.625, 351.875],
             [351.875, 353.125],
             [353.125, 354.375],
             [354.375, 355.625],
             [355.625, 356.875],
             [356.875, 358.125],
             [358.125, 359.375]])
    • tas
      (time, lat, lon)
      float32
      250.6 251.8 250.5 ... 260.5 260.5
      standard_name :
      air_temperature
      long_name :
      Near-Surface Air Temperature
      comment :
      near-surface (usually, 2 meter) air temperature
      units :
      K
      original_name :
      TREFHT
      cell_methods :
      area: time: mean
      cell_measures :
      area: areacella
      history :
      2020-12-21T16:04:10Z altered by CMOR: Treated scalar dimension: 'height'.
      array([[[250.61404, 251.75047, 250.52225, ..., 252.56142, 251.47342,
               251.79126],
              [254.85008, 254.09615, 253.78973, ..., 254.03569, 253.87025,
               253.76013],
              [256.46744, 256.64685, 255.37962, ..., 256.3997 , 255.61328,
               256.78012],
              ...,
              [242.48535, 242.4923 , 242.49825, ..., 242.45024, 242.46492,
               242.47661],
              [242.31367, 242.31175, 242.30966, ..., 242.3185 , 242.31705,
               242.31544],
              [242.38223, 242.38135, 242.38092, ..., 242.38911, 242.38591,
               242.3837 ]],
      
             [[236.34727, 237.33249, 236.30054, ..., 237.68567, 237.16774,
               237.36662],
              [239.92738, 239.17188, 239.00414, ..., 239.1553 , 239.0252 ,
               238.92319],
              [240.41753, 240.37062, 239.55615, ..., 240.1856 , 239.6879 ,
               240.47493],
      ...
              [269.98575, 269.99625, 270.00586, ..., 269.9268 , 269.9517 ,
               269.97202],
              [270.1765 , 270.17908, 270.1819 , ..., 270.1701 , 270.17203,
               270.17416],
              [270.30298, 270.30362, 270.30426, ..., 270.30106, 270.30173,
               270.30234]],
      
             [[250.22421, 250.33122, 250.13512, ..., 250.29846, 250.73671,
               250.27077],
              [255.66652, 253.39455, 255.89824, ..., 253.34317, 253.45265,
               253.16135],
              [258.1754 , 258.03354, 258.20236, ..., 258.30255, 258.38666,
               258.20752],
              ...,
              [260.08542, 260.09125, 260.09604, ..., 260.03867, 260.05966,
               260.07605],
              [260.07614, 260.07715, 260.07825, ..., 260.0736 , 260.07437,
               260.0752 ],
              [260.50592, 260.50662, 260.50824, ..., 260.51108, 260.50784,
               260.50623]]], dtype=float32)
    • time
      PandasIndex
      PandasIndex(CFTimeIndex([1850-01-16 12:00:00, 1850-02-15 00:00:00, 1850-03-16 12:00:00,
                   1850-04-16 00:00:00, 1850-05-16 12:00:00, 1850-06-16 00:00:00,
                   1850-07-16 12:00:00, 1850-08-16 12:00:00, 1850-09-16 00:00:00,
                   1850-10-16 12:00:00,
                   ...
                   2014-03-16 12:00:00, 2014-04-16 00:00:00, 2014-05-16 12:00:00,
                   2014-06-16 00:00:00, 2014-07-16 12:00:00, 2014-08-16 12:00:00,
                   2014-09-16 00:00:00, 2014-10-16 12:00:00, 2014-11-16 00:00:00,
                   2014-12-16 12:00:00],
                  dtype='object', length=1980, calendar='noleap', freq=None))
    • lat
      PandasIndex
      PandasIndex(Index([             -90.0, -89.05759162303664,  -88.1151832460733,
             -87.17277486910994,  -86.2303664921466, -85.28795811518324,
              -84.3455497382199, -83.40314136125654, -82.46073298429319,
             -81.51832460732984,
             ...
              81.51832460732984,   82.4607329842932,  83.40314136125653,
              84.34554973821989,  85.28795811518324,   86.2303664921466,
              87.17277486910996,  88.11518324607329,  89.05759162303664,
                           90.0],
            dtype='float64', name='lat', length=192))
    • lon
      PandasIndex
      PandasIndex(Index([   0.0,   1.25,    2.5,   3.75,    5.0,   6.25,    7.5,   8.75,   10.0,
              11.25,
             ...
              347.5, 348.75,  350.0, 351.25,  352.5, 353.75,  355.0, 356.25,  357.5,
             358.75],
            dtype='float64', name='lon', length=288))
  • Conventions :
    CF-1.7 CMIP-6.2
    activity_id :
    CMIP
    branch_method :
    standard
    branch_time_in_child :
    0.0
    branch_time_in_parent :
    0.0
    comment :
    none
    contact :
    T. Lovato
    creation_date :
    2020-12-21T16:04:17Z
    data_specs_version :
    01.00.31
    experiment :
    all-forcing simulation of the recent past
    experiment_id :
    historical
    external_variables :
    areacella
    forcing_index :
    1
    frequency :
    mon
    further_info_url :
    https://furtherinfo.es-doc.org/CMIP6.CMCC.CMCC-ESM2.historical.none.r1i1p1f1
    grid :
    native atmosphere regular grid
    grid_label :
    gn
    history :
    2020-12-21T16:04:17Z ;rewrote data to be consistent with CMIP for variable tas found in table Amon.; none
    initialization_index :
    1
    institution :
    Fondazione Centro Euro-Mediterraneo sui Cambiamenti Climatici, Lecce 73100, Italy
    institution_id :
    CMCC
    mip_era :
    CMIP6
    nominal_resolution :
    100 km
    parent_activity_id :
    CMIP
    parent_experiment_id :
    piControl
    parent_mip_era :
    CMIP6
    parent_source_id :
    CMCC-ESM2
    parent_time_units :
    days since 1850-01-01
    parent_variant_label :
    r1i1p1f1
    physics_index :
    1
    product :
    model-output
    realization_index :
    1
    realm :
    atmos
    references :
    none
    run_variant :
    1st realization
    source :
    CMCC-ESM2 (2017): aerosol: MAM3 atmos: CAM5.3 (1deg; 288 x 192 longitude/latitude; 30 levels; top at ~2 hPa) atmosChem: none land: CLM4.5 (BGC mode) landIce: none ocean: NEMO3.6 (ORCA1 tripolar primarly 1 deg lat/lon with meridional refinement down to 1/3 degree in the tropics; 362 x 292 longitude/latitude; 50 vertical levels; top grid cell 0-1 m) ocnBgchem: BFM5.1 seaIce: CICE4.0
    source_id :
    CMCC-ESM2
    source_type :
    AOGCM
    sub_experiment :
    none
    sub_experiment_id :
    none
    table_id :
    Amon
    table_info :
    Creation Date:(05 February 2020) MD5:6a248fd76c55aa6d6f7b3cc6866b5faf
    title :
    CMCC-ESM2 output prepared for CMIP6
    variable_id :
    tas
    variant_label :
    r1i1p1f1
    license :
    CMIP6 model data produced by CMCC is licensed under a Creative Commons Attribution ShareAlike 4.0 International License (https://creativecommons.org/licenses). Consult https://pcmdi.llnl.gov/CMIP6/TermsOfUse for terms of use governing CMIP6 output, including citation requirements and proper acknowledgment. Further information about this data, including some limitations, can be found via the further_info_url (recorded as a global attribute in this file) and at https:///pcmdi.llnl.gov/. The data producers and data providers make no warranty, either express or implied, including, but not limited to, warranties of merchantability and fitness for a particular purpose. All liabilities arising from the supply of the information (including any liability arising in negligence) are excluded to the fullest extent permitted by law.
    cmor_version :
    3.6.0
    tracking_id :
    hdl:21.14100/db148e8f-76e1-424c-92e0-8f5abb588c13

Load the ERA5 Reanalysis

In [7]:
file = 'tas_era5_mon_198001-201412.nc'
ds_rean = xr.load_dataset(path+file)
ds_rean
Out[7]:
<xarray.Dataset> Size: 435MB
Dimensions:  (time: 420, lon: 720, lat: 360)
Coordinates:
  * time     (time) datetime64[ns] 3kB 1980-01-01 1980-02-01 ... 2014-12-01
  * lon      (lon) float64 6kB 0.0 0.5 1.0 1.5 2.0 ... 358.0 358.5 359.0 359.5
  * lat      (lat) float64 3kB -89.75 -89.25 -88.75 -88.25 ... 88.75 89.25 89.75
Data variables:
    t2m      (time, lat, lon) float32 435MB 243.7 243.7 243.7 ... 252.3 252.3
Attributes:
    CDI:          Climate Data Interface version 1.9.9rc1 (https://mpimet.mpg...
    Conventions:  CF-1.6
    history:      Wed Nov 27 11:18:27 2024: cdo -L -remapbil,r720x360 -selyea...
    CDO:          Climate Data Operators version 1.9.9rc1 (https://mpimet.mpg...
xarray.Dataset
    • time: 420
    • lon: 720
    • lat: 360
    • time
      (time)
      datetime64[ns]
      1980-01-01 ... 2014-12-01
      standard_name :
      time
      long_name :
      time
      axis :
      T
      array(['1980-01-01T00:00:00.000000000', '1980-02-01T00:00:00.000000000',
             '1980-03-01T00:00:00.000000000', ..., '2014-10-01T00:00:00.000000000',
             '2014-11-01T00:00:00.000000000', '2014-12-01T00:00:00.000000000'],
            dtype='datetime64[ns]')
    • lon
      (lon)
      float64
      0.0 0.5 1.0 ... 358.5 359.0 359.5
      standard_name :
      longitude
      long_name :
      longitude
      units :
      degrees_east
      axis :
      X
      array([  0. ,   0.5,   1. , ..., 358.5, 359. , 359.5])
    • lat
      (lat)
      float64
      -89.75 -89.25 ... 89.25 89.75
      standard_name :
      latitude
      long_name :
      latitude
      units :
      degrees_north
      axis :
      Y
      array([-89.75, -89.25, -88.75, ...,  88.75,  89.25,  89.75])
    • t2m
      (time, lat, lon)
      float32
      243.7 243.7 243.7 ... 252.3 252.3
      long_name :
      2 metre temperature
      units :
      K
      array([[[243.67163, 243.67163, 243.67337, ..., 243.66812, 243.66988,
               243.66988],
              [243.947  , 243.94876, 243.95052, ..., 243.94525, 243.94525,
               243.947  ],
              [244.55215, 244.54689, 244.53813, ..., 244.58023, 244.5697 ,
               244.56093],
              ...,
              [251.47366, 251.45438, 251.43683, ..., 251.52805, 251.50874,
               251.49121],
              [251.26494, 251.25266, 251.24388, ..., 251.29651, 251.28598,
               251.27545],
              [250.75099, 250.74748, 250.74397, ..., 250.76328, 250.75977,
               250.7545 ]],
      
             [[234.52246, 234.52773, 234.52948, ..., 234.51721, 234.51895,
               234.5207 ],
              [234.78032, 234.78732, 234.79434, ..., 234.7733 , 234.77505,
               234.77856],
              [234.24007, 234.2348 , 234.22778, ..., 234.26462, 234.2576 ,
               234.24709],
      ...
              [251.5789 , 251.58592, 251.5947 , ..., 251.55786, 251.56488,
               251.5719 ],
              [251.91743, 251.92094, 251.92445, ..., 251.90341, 251.90868,
               251.91219],
              [252.21388, 252.21564, 252.21564, ..., 252.21037, 252.21213,
               252.21213]],
      
             [[246.49916, 246.49916, 246.4974 , ..., 246.50443, 246.50267,
               246.50267],
              [246.78157, 246.77806, 246.7728 , ..., 246.79033, 246.78683,
               246.78508],
              [246.92365, 246.91136, 246.90085, ..., 246.95697, 246.94469,
               246.93417],
              ...,
              [252.3279 , 252.33665, 252.34367, ..., 252.30684, 252.31386,
               252.32088],
              [252.3086 , 252.31386, 252.31912, ..., 252.29282, 252.29807,
               252.30333],
              [252.3279 , 252.32965, 252.3314 , ..., 252.32263, 252.32439,
               252.32614]]], dtype=float32)
    • time
      PandasIndex
      PandasIndex(DatetimeIndex(['1980-01-01', '1980-02-01', '1980-03-01', '1980-04-01',
                     '1980-05-01', '1980-06-01', '1980-07-01', '1980-08-01',
                     '1980-09-01', '1980-10-01',
                     ...
                     '2014-03-01', '2014-04-01', '2014-05-01', '2014-06-01',
                     '2014-07-01', '2014-08-01', '2014-09-01', '2014-10-01',
                     '2014-11-01', '2014-12-01'],
                    dtype='datetime64[ns]', name='time', length=420, freq=None))
    • lon
      PandasIndex
      PandasIndex(Index([  0.0,   0.5,   1.0,   1.5,   2.0,   2.5,   3.0,   3.5,   4.0,   4.5,
             ...
             355.0, 355.5, 356.0, 356.5, 357.0, 357.5, 358.0, 358.5, 359.0, 359.5],
            dtype='float64', name='lon', length=720))
    • lat
      PandasIndex
      PandasIndex(Index([-89.75, -89.25, -88.75, -88.25, -87.75, -87.25, -86.75, -86.25, -85.75,
             -85.25,
             ...
              85.25,  85.75,  86.25,  86.75,  87.25,  87.75,  88.25,  88.75,  89.25,
              89.75],
            dtype='float64', name='lat', length=360))
  • CDI :
    Climate Data Interface version 1.9.9rc1 (https://mpimet.mpg.de/cdi)
    Conventions :
    CF-1.6
    history :
    Wed Nov 27 11:18:27 2024: cdo -L -remapbil,r720x360 -selyear,1980/2014 era5_tas_195001-201612_raw_f32.nc era5_tas_198001-201412.nc Fri Sep 08 16:22:46 2023: cdo -b F32 mergetime era5_tas_195901-201412_raw.nc test_tas.nc era5_tas_195001-201612_raw.nc 2022-12-22 11:39:38 GMT by grib_to_netcdf-2.25.1: /opt/ecmwf/mars-client/bin/grib_to_netcdf.bin -S param -o /cache/data3/adaptor.mars.internal-1671709161.2343547-29568-18-0f2977b7-3ce1-4988-a8fa-a949a02be9cc.nc /cache/tmp/0f2977b7-3ce1-4988-a8fa-a949a02be9cc-adaptor.mars.internal-1671708984.5017245-29568-22-tmp.grib
    CDO :
    Climate Data Operators version 1.9.9rc1 (https://mpimet.mpg.de/cdo)

Look at the different configuration of the two Dataset. For ESM, our variable of interest is called tas, whereas for the reanalysis it is called t2m.

Coordinates are also named differently (eg lat vs latitude) and stored in a different order.

In [8]:
# Renaming variables

ds_rean = ds_rean.rename(t2m="tas")
ds_rean
Out[8]:
<xarray.Dataset> Size: 435MB
Dimensions:  (time: 420, lon: 720, lat: 360)
Coordinates:
  * time     (time) datetime64[ns] 3kB 1980-01-01 1980-02-01 ... 2014-12-01
  * lon      (lon) float64 6kB 0.0 0.5 1.0 1.5 2.0 ... 358.0 358.5 359.0 359.5
  * lat      (lat) float64 3kB -89.75 -89.25 -88.75 -88.25 ... 88.75 89.25 89.75
Data variables:
    tas      (time, lat, lon) float32 435MB 243.7 243.7 243.7 ... 252.3 252.3
Attributes:
    CDI:          Climate Data Interface version 1.9.9rc1 (https://mpimet.mpg...
    Conventions:  CF-1.6
    history:      Wed Nov 27 11:18:27 2024: cdo -L -remapbil,r720x360 -selyea...
    CDO:          Climate Data Operators version 1.9.9rc1 (https://mpimet.mpg...
xarray.Dataset
    • time: 420
    • lon: 720
    • lat: 360
    • time
      (time)
      datetime64[ns]
      1980-01-01 ... 2014-12-01
      standard_name :
      time
      long_name :
      time
      axis :
      T
      array(['1980-01-01T00:00:00.000000000', '1980-02-01T00:00:00.000000000',
             '1980-03-01T00:00:00.000000000', ..., '2014-10-01T00:00:00.000000000',
             '2014-11-01T00:00:00.000000000', '2014-12-01T00:00:00.000000000'],
            dtype='datetime64[ns]')
    • lon
      (lon)
      float64
      0.0 0.5 1.0 ... 358.5 359.0 359.5
      standard_name :
      longitude
      long_name :
      longitude
      units :
      degrees_east
      axis :
      X
      array([  0. ,   0.5,   1. , ..., 358.5, 359. , 359.5])
    • lat
      (lat)
      float64
      -89.75 -89.25 ... 89.25 89.75
      standard_name :
      latitude
      long_name :
      latitude
      units :
      degrees_north
      axis :
      Y
      array([-89.75, -89.25, -88.75, ...,  88.75,  89.25,  89.75])
    • tas
      (time, lat, lon)
      float32
      243.7 243.7 243.7 ... 252.3 252.3
      long_name :
      2 metre temperature
      units :
      K
      array([[[243.67163, 243.67163, 243.67337, ..., 243.66812, 243.66988,
               243.66988],
              [243.947  , 243.94876, 243.95052, ..., 243.94525, 243.94525,
               243.947  ],
              [244.55215, 244.54689, 244.53813, ..., 244.58023, 244.5697 ,
               244.56093],
              ...,
              [251.47366, 251.45438, 251.43683, ..., 251.52805, 251.50874,
               251.49121],
              [251.26494, 251.25266, 251.24388, ..., 251.29651, 251.28598,
               251.27545],
              [250.75099, 250.74748, 250.74397, ..., 250.76328, 250.75977,
               250.7545 ]],
      
             [[234.52246, 234.52773, 234.52948, ..., 234.51721, 234.51895,
               234.5207 ],
              [234.78032, 234.78732, 234.79434, ..., 234.7733 , 234.77505,
               234.77856],
              [234.24007, 234.2348 , 234.22778, ..., 234.26462, 234.2576 ,
               234.24709],
      ...
              [251.5789 , 251.58592, 251.5947 , ..., 251.55786, 251.56488,
               251.5719 ],
              [251.91743, 251.92094, 251.92445, ..., 251.90341, 251.90868,
               251.91219],
              [252.21388, 252.21564, 252.21564, ..., 252.21037, 252.21213,
               252.21213]],
      
             [[246.49916, 246.49916, 246.4974 , ..., 246.50443, 246.50267,
               246.50267],
              [246.78157, 246.77806, 246.7728 , ..., 246.79033, 246.78683,
               246.78508],
              [246.92365, 246.91136, 246.90085, ..., 246.95697, 246.94469,
               246.93417],
              ...,
              [252.3279 , 252.33665, 252.34367, ..., 252.30684, 252.31386,
               252.32088],
              [252.3086 , 252.31386, 252.31912, ..., 252.29282, 252.29807,
               252.30333],
              [252.3279 , 252.32965, 252.3314 , ..., 252.32263, 252.32439,
               252.32614]]], dtype=float32)
    • time
      PandasIndex
      PandasIndex(DatetimeIndex(['1980-01-01', '1980-02-01', '1980-03-01', '1980-04-01',
                     '1980-05-01', '1980-06-01', '1980-07-01', '1980-08-01',
                     '1980-09-01', '1980-10-01',
                     ...
                     '2014-03-01', '2014-04-01', '2014-05-01', '2014-06-01',
                     '2014-07-01', '2014-08-01', '2014-09-01', '2014-10-01',
                     '2014-11-01', '2014-12-01'],
                    dtype='datetime64[ns]', name='time', length=420, freq=None))
    • lon
      PandasIndex
      PandasIndex(Index([  0.0,   0.5,   1.0,   1.5,   2.0,   2.5,   3.0,   3.5,   4.0,   4.5,
             ...
             355.0, 355.5, 356.0, 356.5, 357.0, 357.5, 358.0, 358.5, 359.0, 359.5],
            dtype='float64', name='lon', length=720))
    • lat
      PandasIndex
      PandasIndex(Index([-89.75, -89.25, -88.75, -88.25, -87.75, -87.25, -86.75, -86.25, -85.75,
             -85.25,
             ...
              85.25,  85.75,  86.25,  86.75,  87.25,  87.75,  88.25,  88.75,  89.25,
              89.75],
            dtype='float64', name='lat', length=360))
  • CDI :
    Climate Data Interface version 1.9.9rc1 (https://mpimet.mpg.de/cdi)
    Conventions :
    CF-1.6
    history :
    Wed Nov 27 11:18:27 2024: cdo -L -remapbil,r720x360 -selyear,1980/2014 era5_tas_195001-201612_raw_f32.nc era5_tas_198001-201412.nc Fri Sep 08 16:22:46 2023: cdo -b F32 mergetime era5_tas_195901-201412_raw.nc test_tas.nc era5_tas_195001-201612_raw.nc 2022-12-22 11:39:38 GMT by grib_to_netcdf-2.25.1: /opt/ecmwf/mars-client/bin/grib_to_netcdf.bin -S param -o /cache/data3/adaptor.mars.internal-1671709161.2343547-29568-18-0f2977b7-3ce1-4988-a8fa-a949a02be9cc.nc /cache/tmp/0f2977b7-3ce1-4988-a8fa-a949a02be9cc-adaptor.mars.internal-1671708984.5017245-29568-22-tmp.grib
    CDO :
    Climate Data Operators version 1.9.9rc1 (https://mpimet.mpg.de/cdo)

If we want to compare the two Datasets, what we need is them to have the same dimensions (Time, Lon and Lat)

In [9]:
# Here we show the resolution of both ESM and Reanalysis
# by looking at the difference among two longitudinal steps

display(ds_rean.lon[1] - ds_rean.lon[0])
display(ds_hist.lon[1] - ds_hist.lon[0])
<xarray.DataArray 'lon' ()> Size: 8B
array(0.5)
xarray.DataArray
'lon'
  • 0.5
    array(0.5)
      <xarray.DataArray 'lon' ()> Size: 8B
      array(1.25)
      Coordinates:
          height   float64 8B 2.0
      xarray.DataArray
      'lon'
      • 1.25
        array(1.25)
        • height
          ()
          float64
          2.0
          units :
          m
          axis :
          Z
          positive :
          up
          long_name :
          height
          standard_name :
          height
          array(2.)
        In [10]:
        # Here we show the resolution of both ESM and Reanalysis
        # by looking at the difference among two latitudinal steps
        
        display(ds_rean.lat[1] - ds_rean.lat[0])
        display(ds_hist.lat[1] - ds_hist.lat[0])
        
        <xarray.DataArray 'lat' ()> Size: 8B
        array(0.5)
        xarray.DataArray
        'lat'
        • 0.5
          array(0.5)
            <xarray.DataArray 'lat' ()> Size: 8B
            array(0.94240838)
            Coordinates:
                height   float64 8B 2.0
            xarray.DataArray
            'lat'
            • 0.9424
              array(0.94240838)
              • height
                ()
                float64
                2.0
                units :
                m
                axis :
                Z
                positive :
                up
                long_name :
                height
                standard_name :
                height
                array(2.)

              In oder to get the same Spatial Resolution (Lat-Lon), we need to process our data through an interpolation algorithm, which allows us to have as a results a Dataset with the same number of Lon and Lat Coordinates (and thus the same resolution!)

              In [11]:
              ds_hist = ds_hist.sel(lat = slice(-85,85))
              ds_rean = ds_rean.sel(lat = slice(-85,85))
              
              In [12]:
              new_lon = np.linspace(ds_hist.lon[0], ds_hist.lon[-1], ds_hist.dims["lon"])
              new_lat = np.linspace(ds_hist.lat[0], ds_hist.lat[-1], ds_hist.dims["lat"])
              
              In [13]:
              ds_rean = ds_rean.interp(lat=new_lat, lon=new_lon)
              display(ds_rean)
              
              <xarray.Dataset> Size: 174MB
              Dimensions:  (time: 420, lat: 180, lon: 288)
              Coordinates:
                * time     (time) datetime64[ns] 3kB 1980-01-01 1980-02-01 ... 2014-12-01
                * lat      (lat) float64 1kB -84.35 -83.4 -82.46 -81.52 ... 82.46 83.4 84.35
                * lon      (lon) float64 2kB 0.0 1.25 2.5 3.75 5.0 ... 355.0 356.2 357.5 358.8
              Data variables:
                  tas      (time, lat, lon) float64 174MB 245.7 245.5 245.4 ... 253.5 253.8
              Attributes:
                  CDI:          Climate Data Interface version 1.9.9rc1 (https://mpimet.mpg...
                  Conventions:  CF-1.6
                  history:      Wed Nov 27 11:18:27 2024: cdo -L -remapbil,r720x360 -selyea...
                  CDO:          Climate Data Operators version 1.9.9rc1 (https://mpimet.mpg...
              xarray.Dataset
                • time: 420
                • lat: 180
                • lon: 288
                • time
                  (time)
                  datetime64[ns]
                  1980-01-01 ... 2014-12-01
                  standard_name :
                  time
                  long_name :
                  time
                  axis :
                  T
                  array(['1980-01-01T00:00:00.000000000', '1980-02-01T00:00:00.000000000',
                         '1980-03-01T00:00:00.000000000', ..., '2014-10-01T00:00:00.000000000',
                         '2014-11-01T00:00:00.000000000', '2014-12-01T00:00:00.000000000'],
                        dtype='datetime64[ns]')
                • lat
                  (lat)
                  float64
                  -84.35 -83.4 -82.46 ... 83.4 84.35
                  standard_name :
                  latitude
                  long_name :
                  latitude
                  units :
                  degrees_north
                  axis :
                  Y
                  array([-84.34555 , -83.403141, -82.460733, -81.518325, -80.575916, -79.633508,
                         -78.691099, -77.748691, -76.806283, -75.863874, -74.921466, -73.979058,
                         -73.036649, -72.094241, -71.151832, -70.209424, -69.267016, -68.324607,
                         -67.382199, -66.439791, -65.497382, -64.554974, -63.612565, -62.670157,
                         -61.727749, -60.78534 , -59.842932, -58.900524, -57.958115, -57.015707,
                         -56.073298, -55.13089 , -54.188482, -53.246073, -52.303665, -51.361257,
                         -50.418848, -49.47644 , -48.534031, -47.591623, -46.649215, -45.706806,
                         -44.764398, -43.82199 , -42.879581, -41.937173, -40.994764, -40.052356,
                         -39.109948, -38.167539, -37.225131, -36.282723, -35.340314, -34.397906,
                         -33.455497, -32.513089, -31.570681, -30.628272, -29.685864, -28.743455,
                         -27.801047, -26.858639, -25.91623 , -24.973822, -24.031414, -23.089005,
                         -22.146597, -21.204188, -20.26178 , -19.319372, -18.376963, -17.434555,
                         -16.492147, -15.549738, -14.60733 , -13.664921, -12.722513, -11.780105,
                         -10.837696,  -9.895288,  -8.95288 ,  -8.010471,  -7.068063,  -6.125654,
                          -5.183246,  -4.240838,  -3.298429,  -2.356021,  -1.413613,  -0.471204,
                           0.471204,   1.413613,   2.356021,   3.298429,   4.240838,   5.183246,
                           6.125654,   7.068063,   8.010471,   8.95288 ,   9.895288,  10.837696,
                          11.780105,  12.722513,  13.664921,  14.60733 ,  15.549738,  16.492147,
                          17.434555,  18.376963,  19.319372,  20.26178 ,  21.204188,  22.146597,
                          23.089005,  24.031414,  24.973822,  25.91623 ,  26.858639,  27.801047,
                          28.743455,  29.685864,  30.628272,  31.570681,  32.513089,  33.455497,
                          34.397906,  35.340314,  36.282723,  37.225131,  38.167539,  39.109948,
                          40.052356,  40.994764,  41.937173,  42.879581,  43.82199 ,  44.764398,
                          45.706806,  46.649215,  47.591623,  48.534031,  49.47644 ,  50.418848,
                          51.361257,  52.303665,  53.246073,  54.188482,  55.13089 ,  56.073298,
                          57.015707,  57.958115,  58.900524,  59.842932,  60.78534 ,  61.727749,
                          62.670157,  63.612565,  64.554974,  65.497382,  66.439791,  67.382199,
                          68.324607,  69.267016,  70.209424,  71.151832,  72.094241,  73.036649,
                          73.979058,  74.921466,  75.863874,  76.806283,  77.748691,  78.691099,
                          79.633508,  80.575916,  81.518325,  82.460733,  83.403141,  84.34555 ])
                • lon
                  (lon)
                  float64
                  0.0 1.25 2.5 ... 356.2 357.5 358.8
                  standard_name :
                  longitude
                  long_name :
                  longitude
                  units :
                  degrees_east
                  axis :
                  X
                  array([  0.  ,   1.25,   2.5 , ..., 356.25, 357.5 , 358.75])
                • tas
                  (time, lat, lon)
                  float64
                  245.7 245.5 245.4 ... 253.5 253.8
                  long_name :
                  2 metre temperature
                  units :
                  K
                  array([[[245.72059316, 245.5312926 , 245.36009692, ..., 246.24421478,
                           246.08093054, 245.89487889],
                          [247.16539409, 246.9187088 , 246.67649769, ..., 247.89591513,
                           247.64393648, 247.41497261],
                          [248.80709743, 248.51332941, 248.1962071 , ..., 249.16667525,
                           249.10696211, 248.98439797],
                          ...,
                          [254.04170163, 253.89852825, 253.73715498, ..., 254.2426738 ,
                           254.20821297, 254.13493022],
                          [253.41792345, 253.22230849, 253.02920157, ..., 253.73031712,
                           253.64131264, 253.53249828],
                          [252.82431833, 252.69802145, 252.57489585, ..., 253.05697951,
                           253.00871117, 252.91526299]],
                  
                         [[235.91703389, 235.72004602, 235.53801643, ..., 236.45652122,
                           236.30165308, 236.10116843],
                          [237.65551706, 237.42765181, 237.1983166 , ..., 238.41880673,
                           238.14569975, 237.91206184],
                          [239.88293078, 239.69506492, 239.46640706, ..., 239.93834359,
                           239.97320101, 239.95077846],
                  ...
                          [254.20467237, 254.09917304, 253.99746125, ..., 254.47081403,
                           254.47629164, 254.3767574 ],
                          [253.09217803, 252.98847826, 252.90725349, ..., 253.23655012,
                           253.22556748, 253.16465386],
                          [252.60220533, 252.61075476, 252.62072362, ..., 252.56134806,
                           252.59735447, 252.60633499]],
                  
                         [[247.3959929 , 247.19056416, 247.00467207, ..., 248.00747473,
                           247.8026322 , 247.60105968],
                          [248.47842954, 248.20727485, 247.94019929, ..., 249.35250349,
                           249.05685253, 248.77545863],
                          [249.89408531, 249.58577115, 249.26057051, ..., 250.56348333,
                           250.3814148 , 250.15861443],
                          ...,
                          [256.16078534, 256.33042454, 256.46932017, ..., 255.49195972,
                           255.73015263, 255.95473466],
                          [255.0239807 , 255.17610903, 255.32197627, ..., 254.45426306,
                           254.58153222, 254.79885423],
                          [254.00857488, 254.21679166, 254.4317579 , ..., 253.37831963,
                           253.53303332, 253.76704736]]])
                • time
                  PandasIndex
                  PandasIndex(DatetimeIndex(['1980-01-01', '1980-02-01', '1980-03-01', '1980-04-01',
                                 '1980-05-01', '1980-06-01', '1980-07-01', '1980-08-01',
                                 '1980-09-01', '1980-10-01',
                                 ...
                                 '2014-03-01', '2014-04-01', '2014-05-01', '2014-06-01',
                                 '2014-07-01', '2014-08-01', '2014-09-01', '2014-10-01',
                                 '2014-11-01', '2014-12-01'],
                                dtype='datetime64[ns]', name='time', length=420, freq=None))
                • lat
                  PandasIndex
                  PandasIndex(Index([ -84.3455497382199, -83.40314136125654,  -82.4607329842932,
                         -81.51832460732984,  -80.5759162303665, -79.63350785340315,
                          -78.6910994764398, -77.74869109947645, -76.80628272251309,
                         -75.86387434554975,
                         ...
                          75.86387434554972,  76.80628272251307,   77.7486910994764,
                          78.69109947643976,  79.63350785340312,  80.57591623036647,
                          81.51832460732983,  82.46073298429316,  83.40314136125652,
                          84.34554973821989],
                        dtype='float64', name='lat', length=180))
                • lon
                  PandasIndex
                  PandasIndex(Index([   0.0,   1.25,    2.5,   3.75,    5.0,   6.25,    7.5,   8.75,   10.0,
                          11.25,
                         ...
                          347.5, 348.75,  350.0, 351.25,  352.5, 353.75,  355.0, 356.25,  357.5,
                         358.75],
                        dtype='float64', name='lon', length=288))
              • CDI :
                Climate Data Interface version 1.9.9rc1 (https://mpimet.mpg.de/cdi)
                Conventions :
                CF-1.6
                history :
                Wed Nov 27 11:18:27 2024: cdo -L -remapbil,r720x360 -selyear,1980/2014 era5_tas_195001-201612_raw_f32.nc era5_tas_198001-201412.nc Fri Sep 08 16:22:46 2023: cdo -b F32 mergetime era5_tas_195901-201412_raw.nc test_tas.nc era5_tas_195001-201612_raw.nc 2022-12-22 11:39:38 GMT by grib_to_netcdf-2.25.1: /opt/ecmwf/mars-client/bin/grib_to_netcdf.bin -S param -o /cache/data3/adaptor.mars.internal-1671709161.2343547-29568-18-0f2977b7-3ce1-4988-a8fa-a949a02be9cc.nc /cache/tmp/0f2977b7-3ce1-4988-a8fa-a949a02be9cc-adaptor.mars.internal-1671708984.5017245-29568-22-tmp.grib
                CDO :
                Climate Data Operators version 1.9.9rc1 (https://mpimet.mpg.de/cdo)
              In [14]:
              # Define Variable an convert Kelvin to Celsius
              
              var = "tas"
              
              ds_hist[var] = ds_hist[var] - 273.15
              ds_rean[var] = ds_rean[var] - 273.15
              
              In [15]:
              fig = plt.figure(1, figsize=[20,13])
              
              # Set the projection to use for plotting
              ax1 = plt.subplot(1, 2, 1, projection=ccrs.Orthographic(30, 45))
              ax2 = plt.subplot(1, 2, 2, projection=ccrs.Orthographic(30, 45))
              
              # Fix extent
              minval = -35
              maxval = 30
              
              tsel = "2010-01"
              
              map = ds_hist[var].sel(time=tsel).mean("time").plot(ax=ax1, vmin=minval, vmax=maxval,
                                                         transform=ccrs.PlateCarree(),
                                                         cmap='coolwarm',
                                                         add_colorbar=False)
              
              map = ds_rean[var].sel(time=tsel).mean("time").plot(ax=ax2, vmin=minval, vmax=maxval,
                                                         transform=ccrs.PlateCarree(),
                                                         cmap='coolwarm',
                                                         add_colorbar=False)
              
              
              
              ax1.set_title(ds_hist.attrs['parent_source_id'] , fontsize=18, pad = 30)
              ax1.coastlines()
              ax1.gridlines()
              
              ax2.set_title("ERA5 Reanalysis" , fontsize=18, pad = 30)
              ax2.coastlines()
              ax2.gridlines()
              
              # Title for both plots
              fig.suptitle('Near Surface Temperature\n' + ds_hist[var].sel(time=tsel).time.values[0].strftime("%B %Y"), fontsize=20)
              
              
              cb_ax = fig.add_axes([0.325, 0.05, 0.4, 0.04])
              
              cbar = plt.colorbar(map, cax=cb_ax, extend='both', orientation='horizontal', fraction=0.046, pad=0.04)
              cbar.ax.tick_params(labelsize=25)
              cbar.ax.set_xlabel('K', fontsize=25)
              
              Out[15]:
              Text(0.5, 0, 'K')
              No description has been provided for this image

              Now we want to calculate the BIAS, so the deviation of the ESM from the quasi-observation of ERA5

              In [16]:
              # To compute the difference, we need not only Longitude and Latitude to have the same resolution
              # but also the Dataarray need to have the same calendar
              
              ds_hist.indexes['time']
              ds_rean.indexes['time']
              
              Out[16]:
              DatetimeIndex(['1980-01-01', '1980-02-01', '1980-03-01', '1980-04-01',
                             '1980-05-01', '1980-06-01', '1980-07-01', '1980-08-01',
                             '1980-09-01', '1980-10-01',
                             ...
                             '2014-03-01', '2014-04-01', '2014-05-01', '2014-06-01',
                             '2014-07-01', '2014-08-01', '2014-09-01', '2014-10-01',
                             '2014-11-01', '2014-12-01'],
                            dtype='datetime64[ns]', name='time', length=420, freq=None)
              In [17]:
              # We can (luckily) easily convert our ESM cftime object to a standard datetime calendar
              
              ds_hist['time'] = ds_hist.indexes['time'].to_datetimeindex()
              
              In [18]:
              # Let's compute the monthly bias
              # Avoid lat to have different decimal approximations
              ds_rean["lat"] = ds_hist["lat"]
              
              bias = ds_hist.sel(time=slice("1985-01", "2012-12"))[var].groupby("time.month").mean() - ds_rean.sel(time=slice("1985-01", "2012-12"))[var].groupby("time.month").mean()
              
              In [45]:
              bias
              
              Out[45]:
              <xarray.DataArray 'tas' (month: 12, lat: 180, lon: 288)> Size: 5MB
              array([[[ 1.64889674e+01,  1.66940977e+01,  1.68836072e+01, ...,
                        1.59889070e+01,  1.61066128e+01,  1.62901588e+01],
                      [ 1.65941248e+01,  1.67351204e+01,  1.68765994e+01, ...,
                        1.60792946e+01,  1.62728476e+01,  1.64288068e+01],
                      [ 1.54238564e+01,  1.55769782e+01,  1.57365223e+01, ...,
                        1.52806500e+01,  1.53040472e+01,  1.53362429e+01],
                      ...,
                      [ 1.77578706e+00,  1.76636712e+00,  1.89309015e+00, ...,
                        1.38125712e+00,  1.40788316e+00,  1.48915636e+00],
                      [ 1.54159925e+00,  1.64307328e+00,  1.83063771e+00, ...,
                        1.18790185e+00,  1.32891273e+00,  1.56014794e+00],
                      [ 1.50327769e+00,  1.64545661e+00,  1.72166372e+00, ...,
                        1.35950020e+00,  1.48421933e+00,  1.41739397e+00]],
              
                     [[ 8.03404438e+00,  8.25476594e+00,  8.41631052e+00, ...,
                        7.56203812e+00,  7.68765286e+00,  7.84602315e+00],
                      [ 7.90515559e+00,  8.06203348e+00,  8.25514758e+00, ...,
                        7.20658530e+00,  7.47359527e+00,  7.67860772e+00],
                      [ 6.92701231e+00,  7.09217065e+00,  7.28362882e+00, ...,
                        6.96183646e+00,  6.90120320e+00,  6.89973894e+00],
              ...
                      [ 1.29017980e+01,  1.27914284e+01,  1.27198947e+01, ...,
                        1.28600837e+01,  1.28500867e+01,  1.28272513e+01],
                      [ 1.32103924e+01,  1.31795545e+01,  1.31949351e+01, ...,
                        1.31409008e+01,  1.31940700e+01,  1.32831634e+01],
                      [ 1.34308371e+01,  1.34325425e+01,  1.33971132e+01, ...,
                        1.34894616e+01,  1.35176018e+01,  1.34337364e+01]],
              
                     [[ 1.30764638e+01,  1.33196065e+01,  1.34165801e+01, ...,
                        1.27096464e+01,  1.27669990e+01,  1.28779556e+01],
                      [ 1.35786331e+01,  1.36738726e+01,  1.37326310e+01, ...,
                        1.32736144e+01,  1.34413434e+01,  1.34939170e+01],
                      [ 1.27379153e+01,  1.28339086e+01,  1.29230645e+01, ...,
                        1.27891203e+01,  1.27109665e+01,  1.26963668e+01],
                      ...,
                      [ 7.00109978e+00,  6.92451283e+00,  6.96604920e+00, ...,
                        6.77596684e+00,  6.76966168e+00,  6.80250334e+00],
                      [ 7.02236872e+00,  7.03408503e+00,  7.10957152e+00, ...,
                        6.92026798e+00,  6.99273425e+00,  7.11189207e+00],
                      [ 7.21322395e+00,  7.25525065e+00,  7.24929960e+00, ...,
                        7.23987411e+00,  7.29118245e+00,  7.19961694e+00]]])
              Coordinates:
                * lat      (lat) float64 1kB -84.35 -83.4 -82.46 -81.52 ... 82.46 83.4 84.35
                * lon      (lon) float64 2kB 0.0 1.25 2.5 3.75 5.0 ... 355.0 356.2 357.5 358.8
                  height   float64 8B 2.0
                * month    (month) int64 96B 1 2 3 4 5 6 7 8 9 10 11 12
              xarray.DataArray
              'tas'
              • month: 12
              • lat: 180
              • lon: 288
              • 16.49 16.69 16.88 17.06 17.23 17.35 ... 7.142 7.099 7.24 7.291 7.2
                array([[[ 1.64889674e+01,  1.66940977e+01,  1.68836072e+01, ...,
                          1.59889070e+01,  1.61066128e+01,  1.62901588e+01],
                        [ 1.65941248e+01,  1.67351204e+01,  1.68765994e+01, ...,
                          1.60792946e+01,  1.62728476e+01,  1.64288068e+01],
                        [ 1.54238564e+01,  1.55769782e+01,  1.57365223e+01, ...,
                          1.52806500e+01,  1.53040472e+01,  1.53362429e+01],
                        ...,
                        [ 1.77578706e+00,  1.76636712e+00,  1.89309015e+00, ...,
                          1.38125712e+00,  1.40788316e+00,  1.48915636e+00],
                        [ 1.54159925e+00,  1.64307328e+00,  1.83063771e+00, ...,
                          1.18790185e+00,  1.32891273e+00,  1.56014794e+00],
                        [ 1.50327769e+00,  1.64545661e+00,  1.72166372e+00, ...,
                          1.35950020e+00,  1.48421933e+00,  1.41739397e+00]],
                
                       [[ 8.03404438e+00,  8.25476594e+00,  8.41631052e+00, ...,
                          7.56203812e+00,  7.68765286e+00,  7.84602315e+00],
                        [ 7.90515559e+00,  8.06203348e+00,  8.25514758e+00, ...,
                          7.20658530e+00,  7.47359527e+00,  7.67860772e+00],
                        [ 6.92701231e+00,  7.09217065e+00,  7.28362882e+00, ...,
                          6.96183646e+00,  6.90120320e+00,  6.89973894e+00],
                ...
                        [ 1.29017980e+01,  1.27914284e+01,  1.27198947e+01, ...,
                          1.28600837e+01,  1.28500867e+01,  1.28272513e+01],
                        [ 1.32103924e+01,  1.31795545e+01,  1.31949351e+01, ...,
                          1.31409008e+01,  1.31940700e+01,  1.32831634e+01],
                        [ 1.34308371e+01,  1.34325425e+01,  1.33971132e+01, ...,
                          1.34894616e+01,  1.35176018e+01,  1.34337364e+01]],
                
                       [[ 1.30764638e+01,  1.33196065e+01,  1.34165801e+01, ...,
                          1.27096464e+01,  1.27669990e+01,  1.28779556e+01],
                        [ 1.35786331e+01,  1.36738726e+01,  1.37326310e+01, ...,
                          1.32736144e+01,  1.34413434e+01,  1.34939170e+01],
                        [ 1.27379153e+01,  1.28339086e+01,  1.29230645e+01, ...,
                          1.27891203e+01,  1.27109665e+01,  1.26963668e+01],
                        ...,
                        [ 7.00109978e+00,  6.92451283e+00,  6.96604920e+00, ...,
                          6.77596684e+00,  6.76966168e+00,  6.80250334e+00],
                        [ 7.02236872e+00,  7.03408503e+00,  7.10957152e+00, ...,
                          6.92026798e+00,  6.99273425e+00,  7.11189207e+00],
                        [ 7.21322395e+00,  7.25525065e+00,  7.24929960e+00, ...,
                          7.23987411e+00,  7.29118245e+00,  7.19961694e+00]]])
                • lat
                  (lat)
                  float64
                  -84.35 -83.4 -82.46 ... 83.4 84.35
                  bounds :
                  lat_bnds
                  units :
                  degrees_north
                  axis :
                  Y
                  long_name :
                  Latitude
                  standard_name :
                  latitude
                  array([-84.34555 , -83.403141, -82.460733, -81.518325, -80.575916, -79.633508,
                         -78.691099, -77.748691, -76.806283, -75.863874, -74.921466, -73.979058,
                         -73.036649, -72.094241, -71.151832, -70.209424, -69.267016, -68.324607,
                         -67.382199, -66.439791, -65.497382, -64.554974, -63.612565, -62.670157,
                         -61.727749, -60.78534 , -59.842932, -58.900524, -57.958115, -57.015707,
                         -56.073298, -55.13089 , -54.188482, -53.246073, -52.303665, -51.361257,
                         -50.418848, -49.47644 , -48.534031, -47.591623, -46.649215, -45.706806,
                         -44.764398, -43.82199 , -42.879581, -41.937173, -40.994764, -40.052356,
                         -39.109948, -38.167539, -37.225131, -36.282723, -35.340314, -34.397906,
                         -33.455497, -32.513089, -31.570681, -30.628272, -29.685864, -28.743455,
                         -27.801047, -26.858639, -25.91623 , -24.973822, -24.031414, -23.089005,
                         -22.146597, -21.204188, -20.26178 , -19.319372, -18.376963, -17.434555,
                         -16.492147, -15.549738, -14.60733 , -13.664921, -12.722513, -11.780105,
                         -10.837696,  -9.895288,  -8.95288 ,  -8.010471,  -7.068063,  -6.125654,
                          -5.183246,  -4.240838,  -3.298429,  -2.356021,  -1.413613,  -0.471204,
                           0.471204,   1.413613,   2.356021,   3.298429,   4.240838,   5.183246,
                           6.125654,   7.068063,   8.010471,   8.95288 ,   9.895288,  10.837696,
                          11.780105,  12.722513,  13.664921,  14.60733 ,  15.549738,  16.492147,
                          17.434555,  18.376963,  19.319372,  20.26178 ,  21.204188,  22.146597,
                          23.089005,  24.031414,  24.973822,  25.91623 ,  26.858639,  27.801047,
                          28.743455,  29.685864,  30.628272,  31.570681,  32.513089,  33.455497,
                          34.397906,  35.340314,  36.282723,  37.225131,  38.167539,  39.109948,
                          40.052356,  40.994764,  41.937173,  42.879581,  43.82199 ,  44.764398,
                          45.706806,  46.649215,  47.591623,  48.534031,  49.47644 ,  50.418848,
                          51.361257,  52.303665,  53.246073,  54.188482,  55.13089 ,  56.073298,
                          57.015707,  57.958115,  58.900524,  59.842932,  60.78534 ,  61.727749,
                          62.670157,  63.612565,  64.554974,  65.497382,  66.439791,  67.382199,
                          68.324607,  69.267016,  70.209424,  71.151832,  72.094241,  73.036649,
                          73.979058,  74.921466,  75.863874,  76.806283,  77.748691,  78.691099,
                          79.633508,  80.575916,  81.518325,  82.460733,  83.403141,  84.34555 ])
                • lon
                  (lon)
                  float64
                  0.0 1.25 2.5 ... 356.2 357.5 358.8
                  bounds :
                  lon_bnds
                  units :
                  degrees_east
                  axis :
                  X
                  long_name :
                  Longitude
                  standard_name :
                  longitude
                  array([  0.  ,   1.25,   2.5 , ..., 356.25, 357.5 , 358.75])
                • height
                  ()
                  float64
                  2.0
                  units :
                  m
                  axis :
                  Z
                  positive :
                  up
                  long_name :
                  height
                  standard_name :
                  height
                  array(2.)
                • month
                  (month)
                  int64
                  1 2 3 4 5 6 7 8 9 10 11 12
                  array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12])
                • lat
                  PandasIndex
                  PandasIndex(Index([ -84.3455497382199, -83.40314136125654, -82.46073298429319,
                         -81.51832460732984, -80.57591623036649, -79.63350785340315,
                         -78.69109947643979, -77.74869109947645, -76.80628272251309,
                         -75.86387434554973,
                         ...
                          75.86387434554973,  76.80628272251309,  77.74869109947645,
                           78.6910994764398,  79.63350785340313,  80.57591623036649,
                          81.51832460732984,   82.4607329842932,  83.40314136125653,
                          84.34554973821989],
                        dtype='float64', name='lat', length=180))
                • lon
                  PandasIndex
                  PandasIndex(Index([   0.0,   1.25,    2.5,   3.75,    5.0,   6.25,    7.5,   8.75,   10.0,
                          11.25,
                         ...
                          347.5, 348.75,  350.0, 351.25,  352.5, 353.75,  355.0, 356.25,  357.5,
                         358.75],
                        dtype='float64', name='lon', length=288))
                • month
                  PandasIndex
                  PandasIndex(Index([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], dtype='int64', name='month'))
              In [19]:
              fig = plt.figure(1, figsize=[20,13])
              
              # Set the projection to use for plotting
              ax1 = plt.subplot(1, 2, 1, projection=ccrs.Orthographic(-30, -30))
              ax2 = plt.subplot(1, 2, 2, projection=ccrs.Orthographic(30, 45))
              
              # Fix MIN and MAX colorbar extent
              minval = -10
              maxval = 10
              
              map = bias.sel(month =1).plot(ax=ax1, vmin=minval, vmax=maxval,
                                                         transform=ccrs.PlateCarree(),
                                                         cmap='coolwarm',
                                                         add_colorbar=False)
              
              map = bias.sel(month = 8).plot(ax=ax2, vmin=minval, vmax=maxval,
                                                         transform=ccrs.PlateCarree(),
                                                         cmap='coolwarm',
                                                         add_colorbar=False)
              
              
              
              ax1.set_title("January" , fontsize=18, pad = 30)
              ax1.coastlines()
              ax1.gridlines()
              
              ax2.set_title("July" , fontsize=18, pad = 30)
              ax2.coastlines()
              ax2.gridlines()
              
              # Title for both plots
              fig.suptitle('Near Surface Temperature Bias', fontsize=20, y = 0.9)
              
              
              cb_ax = fig.add_axes([0.325, 0.05, 0.4, 0.04])
              
              cbar = plt.colorbar(map, cax=cb_ax, extend='both', orientation='horizontal', fraction=0.046)
              cbar.ax.tick_params(labelsize=25)
              cbar.ax.set_xlabel('K', fontsize=25)
              
              Out[19]:
              Text(0.5, 0, 'K')
              No description has been provided for this image

              Historical - SSP245 scenario¶

              Now, let's take a look at what the temperature could look like in a medium increase warming scenario, the SSP245.

              In [20]:
              # Import SSP245 and convert from Kelvin to Celsius
              
              file = 'tas_Amon_CMCC-ESM2_ssp245_r1i1p1f1_gn_201501-210012.nc'
              ds_ssp = xr.load_dataset(path+file)
              ds_ssp[var].data = ds_ssp[var].data - 273.15
              ds_ssp['time'] = ds_ssp.indexes['time'].to_datetimeindex()
              ds_ssp
              
              Out[20]:
              <xarray.Dataset> Size: 228MB
              Dimensions:    (time: 1032, bnds: 2, lat: 192, lon: 288)
              Coordinates:
                * time       (time) datetime64[ns] 8kB 2015-01-16T12:00:00 ... 2100-12-16T1...
                * lat        (lat) float64 2kB -90.0 -89.06 -88.12 -87.17 ... 88.12 89.06 90.0
                * lon        (lon) float64 2kB 0.0 1.25 2.5 3.75 ... 355.0 356.2 357.5 358.8
                  height     float64 8B 2.0
              Dimensions without coordinates: bnds
              Data variables:
                  time_bnds  (time, bnds) object 17kB 2015-01-01 00:00:00 ... 2101-01-01 00...
                  lat_bnds   (lat, bnds) float64 3kB -90.0 -89.53 -89.53 ... 89.53 89.53 90.0
                  lon_bnds   (lon, bnds) float64 5kB -0.625 0.625 0.625 ... 358.1 358.1 359.4
                  tas        (time, lat, lon) float32 228MB -19.72 -19.55 ... 0.5884 0.5883
              Attributes: (12/48)
                  Conventions:            CF-1.7 CMIP-6.2
                  activity_id:            ScenarioMIP
                  branch_method:          standard
                  branch_time_in_child:   60225.0
                  branch_time_in_parent:  60225.0
                  comment:                none
                  ...                     ...
                  title:                  CMCC-ESM2 output prepared for CMIP6
                  variable_id:            tas
                  variant_label:          r1i1p1f1
                  license:                CMIP6 model data produced by CMCC is licensed und...
                  cmor_version:           3.6.0
                  tracking_id:            hdl:21.14100/90a9919e-6c68-4b66-98a7-4382e9f799b3
              xarray.Dataset
                • time: 1032
                • bnds: 2
                • lat: 192
                • lon: 288
                • time
                  (time)
                  datetime64[ns]
                  2015-01-16T12:00:00 ... 2100-12-...
                  array(['2015-01-16T12:00:00.000000000', '2015-02-15T00:00:00.000000000',
                         '2015-03-16T12:00:00.000000000', ..., '2100-10-16T12:00:00.000000000',
                         '2100-11-16T00:00:00.000000000', '2100-12-16T12:00:00.000000000'],
                        dtype='datetime64[ns]')
                • lat
                  (lat)
                  float64
                  -90.0 -89.06 -88.12 ... 89.06 90.0
                  bounds :
                  lat_bnds
                  units :
                  degrees_north
                  axis :
                  Y
                  long_name :
                  Latitude
                  standard_name :
                  latitude
                  array([-90.      , -89.057592, -88.115183, -87.172775, -86.230366, -85.287958,
                         -84.34555 , -83.403141, -82.460733, -81.518325, -80.575916, -79.633508,
                         -78.691099, -77.748691, -76.806283, -75.863874, -74.921466, -73.979058,
                         -73.036649, -72.094241, -71.151832, -70.209424, -69.267016, -68.324607,
                         -67.382199, -66.439791, -65.497382, -64.554974, -63.612565, -62.670157,
                         -61.727749, -60.78534 , -59.842932, -58.900524, -57.958115, -57.015707,
                         -56.073298, -55.13089 , -54.188482, -53.246073, -52.303665, -51.361257,
                         -50.418848, -49.47644 , -48.534031, -47.591623, -46.649215, -45.706806,
                         -44.764398, -43.82199 , -42.879581, -41.937173, -40.994764, -40.052356,
                         -39.109948, -38.167539, -37.225131, -36.282723, -35.340314, -34.397906,
                         -33.455497, -32.513089, -31.570681, -30.628272, -29.685864, -28.743455,
                         -27.801047, -26.858639, -25.91623 , -24.973822, -24.031414, -23.089005,
                         -22.146597, -21.204188, -20.26178 , -19.319372, -18.376963, -17.434555,
                         -16.492147, -15.549738, -14.60733 , -13.664921, -12.722513, -11.780105,
                         -10.837696,  -9.895288,  -8.95288 ,  -8.010471,  -7.068063,  -6.125654,
                          -5.183246,  -4.240838,  -3.298429,  -2.356021,  -1.413613,  -0.471204,
                           0.471204,   1.413613,   2.356021,   3.298429,   4.240838,   5.183246,
                           6.125654,   7.068063,   8.010471,   8.95288 ,   9.895288,  10.837696,
                          11.780105,  12.722513,  13.664921,  14.60733 ,  15.549738,  16.492147,
                          17.434555,  18.376963,  19.319372,  20.26178 ,  21.204188,  22.146597,
                          23.089005,  24.031414,  24.973822,  25.91623 ,  26.858639,  27.801047,
                          28.743455,  29.685864,  30.628272,  31.570681,  32.513089,  33.455497,
                          34.397906,  35.340314,  36.282723,  37.225131,  38.167539,  39.109948,
                          40.052356,  40.994764,  41.937173,  42.879581,  43.82199 ,  44.764398,
                          45.706806,  46.649215,  47.591623,  48.534031,  49.47644 ,  50.418848,
                          51.361257,  52.303665,  53.246073,  54.188482,  55.13089 ,  56.073298,
                          57.015707,  57.958115,  58.900524,  59.842932,  60.78534 ,  61.727749,
                          62.670157,  63.612565,  64.554974,  65.497382,  66.439791,  67.382199,
                          68.324607,  69.267016,  70.209424,  71.151832,  72.094241,  73.036649,
                          73.979058,  74.921466,  75.863874,  76.806283,  77.748691,  78.691099,
                          79.633508,  80.575916,  81.518325,  82.460733,  83.403141,  84.34555 ,
                          85.287958,  86.230366,  87.172775,  88.115183,  89.057592,  90.      ])
                • lon
                  (lon)
                  float64
                  0.0 1.25 2.5 ... 356.2 357.5 358.8
                  bounds :
                  lon_bnds
                  units :
                  degrees_east
                  axis :
                  X
                  long_name :
                  Longitude
                  standard_name :
                  longitude
                  array([  0.  ,   1.25,   2.5 , ..., 356.25, 357.5 , 358.75])
                • height
                  ()
                  float64
                  2.0
                  units :
                  m
                  axis :
                  Z
                  positive :
                  up
                  long_name :
                  height
                  standard_name :
                  height
                  array(2.)
                • time_bnds
                  (time, bnds)
                  object
                  2015-01-01 00:00:00 ... 2101-01-...
                  array([[cftime.DatetimeNoLeap(2015, 1, 1, 0, 0, 0, 0, has_year_zero=True),
                          cftime.DatetimeNoLeap(2015, 2, 1, 0, 0, 0, 0, has_year_zero=True)],
                         [cftime.DatetimeNoLeap(2015, 2, 1, 0, 0, 0, 0, has_year_zero=True),
                          cftime.DatetimeNoLeap(2015, 3, 1, 0, 0, 0, 0, has_year_zero=True)],
                         [cftime.DatetimeNoLeap(2015, 3, 1, 0, 0, 0, 0, has_year_zero=True),
                          cftime.DatetimeNoLeap(2015, 4, 1, 0, 0, 0, 0, has_year_zero=True)],
                         ...,
                         [cftime.DatetimeNoLeap(2100, 10, 1, 0, 0, 0, 0, has_year_zero=True),
                          cftime.DatetimeNoLeap(2100, 11, 1, 0, 0, 0, 0, has_year_zero=True)],
                         [cftime.DatetimeNoLeap(2100, 11, 1, 0, 0, 0, 0, has_year_zero=True),
                          cftime.DatetimeNoLeap(2100, 12, 1, 0, 0, 0, 0, has_year_zero=True)],
                         [cftime.DatetimeNoLeap(2100, 12, 1, 0, 0, 0, 0, has_year_zero=True),
                          cftime.DatetimeNoLeap(2101, 1, 1, 0, 0, 0, 0, has_year_zero=True)]],
                        dtype=object)
                • lat_bnds
                  (lat, bnds)
                  float64
                  -90.0 -89.53 -89.53 ... 89.53 90.0
                  array([[-90.        , -89.52879581],
                         [-89.52879581, -88.58638743],
                         [-88.58638743, -87.64397906],
                         [-87.64397906, -86.70157068],
                         [-86.70157068, -85.7591623 ],
                         [-85.7591623 , -84.81675393],
                         [-84.81675393, -83.87434555],
                         [-83.87434555, -82.93193717],
                         [-82.93193717, -81.9895288 ],
                         [-81.9895288 , -81.04712042],
                         [-81.04712042, -80.10471204],
                         [-80.10471204, -79.16230366],
                         [-79.16230366, -78.21989529],
                         [-78.21989529, -77.27748691],
                         [-77.27748691, -76.33507853],
                         [-76.33507853, -75.39267016],
                         [-75.39267016, -74.45026178],
                         [-74.45026178, -73.5078534 ],
                         [-73.5078534 , -72.56544503],
                         [-72.56544503, -71.62303665],
                  ...
                         [ 71.62303665,  72.56544503],
                         [ 72.56544503,  73.5078534 ],
                         [ 73.5078534 ,  74.45026178],
                         [ 74.45026178,  75.39267016],
                         [ 75.39267016,  76.33507853],
                         [ 76.33507853,  77.27748691],
                         [ 77.27748691,  78.21989529],
                         [ 78.21989529,  79.16230366],
                         [ 79.16230366,  80.10471204],
                         [ 80.10471204,  81.04712042],
                         [ 81.04712042,  81.9895288 ],
                         [ 81.9895288 ,  82.93193717],
                         [ 82.93193717,  83.87434555],
                         [ 83.87434555,  84.81675393],
                         [ 84.81675393,  85.7591623 ],
                         [ 85.7591623 ,  86.70157068],
                         [ 86.70157068,  87.64397906],
                         [ 87.64397906,  88.58638743],
                         [ 88.58638743,  89.52879581],
                         [ 89.52879581,  90.        ]])
                • lon_bnds
                  (lon, bnds)
                  float64
                  -0.625 0.625 0.625 ... 358.1 359.4
                  array([[ -0.625,   0.625],
                         [  0.625,   1.875],
                         [  1.875,   3.125],
                         [  3.125,   4.375],
                         [  4.375,   5.625],
                         [  5.625,   6.875],
                         [  6.875,   8.125],
                         [  8.125,   9.375],
                         [  9.375,  10.625],
                         [ 10.625,  11.875],
                         [ 11.875,  13.125],
                         [ 13.125,  14.375],
                         [ 14.375,  15.625],
                         [ 15.625,  16.875],
                         [ 16.875,  18.125],
                         [ 18.125,  19.375],
                         [ 19.375,  20.625],
                         [ 20.625,  21.875],
                         [ 21.875,  23.125],
                         [ 23.125,  24.375],
                  ...
                         [334.375, 335.625],
                         [335.625, 336.875],
                         [336.875, 338.125],
                         [338.125, 339.375],
                         [339.375, 340.625],
                         [340.625, 341.875],
                         [341.875, 343.125],
                         [343.125, 344.375],
                         [344.375, 345.625],
                         [345.625, 346.875],
                         [346.875, 348.125],
                         [348.125, 349.375],
                         [349.375, 350.625],
                         [350.625, 351.875],
                         [351.875, 353.125],
                         [353.125, 354.375],
                         [354.375, 355.625],
                         [355.625, 356.875],
                         [356.875, 358.125],
                         [358.125, 359.375]])
                • tas
                  (time, lat, lon)
                  float32
                  -19.72 -19.55 ... 0.5884 0.5883
                  standard_name :
                  air_temperature
                  long_name :
                  Near-Surface Air Temperature
                  comment :
                  near-surface (usually, 2 meter) air temperature
                  units :
                  K
                  original_name :
                  TREFHT
                  cell_methods :
                  area: time: mean
                  cell_measures :
                  area: areacella
                  history :
                  2021-01-28T23:58:57Z altered by CMOR: Treated scalar dimension: 'height'.
                  array([[[-19.719818  , -19.54715   , -19.826126  , ..., -19.554062  ,
                           -18.577942  , -19.640945  ],
                          [-13.881012  , -15.695129  , -13.996857  , ..., -15.783905  ,
                           -15.679535  , -16.167084  ],
                          [-11.885834  , -11.937714  , -11.9869995 , ..., -11.763489  ,
                           -11.849518  , -11.84317   ],
                          ...,
                          [-18.568787  , -18.538986  , -18.514465  , ..., -18.736053  ,
                           -18.664581  , -18.60849   ],
                          [-18.747208  , -18.745987  , -18.74466   , ..., -18.75026   ,
                           -18.749329  , -18.748322  ],
                          [-18.666946  , -18.66597   , -18.66507   , ..., -18.670822  ,
                           -18.669312  , -18.668045  ]],
                  
                         [[-31.48581   , -31.44014   , -31.497238  , ..., -31.450333  ,
                           -31.13704   , -31.46083   ],
                          [-28.175186  , -29.107315  , -28.346985  , ..., -29.165161  ,
                           -29.14241   , -29.432327  ],
                          [-27.227951  , -27.239914  , -27.33342   , ..., -27.161346  ,
                           -27.235092  , -27.210434  ],
                  ...
                          [  1.7059937 ,   1.7132568 ,   1.719574  , ...,   1.6812439 ,
                             1.6905823 ,   1.6982422 ],
                          [  1.7256165 ,   1.7261658 ,   1.7267761 , ...,   1.7242432 ,
                             1.7246704 ,   1.7251282 ],
                          [  1.7731018 ,   1.7736206 ,   1.7741089 , ...,   1.7711792 ,
                             1.7719116 ,   1.772522  ]],
                  
                         [[-14.392029  , -14.410004  , -14.397583  , ..., -14.423462  ,
                           -14.4114685 , -14.400696  ],
                          [-13.410919  , -13.45224   , -13.492615  , ..., -16.481628  ,
                           -13.559479  , -14.515411  ],
                          [-12.016266  , -11.990265  , -12.005829  , ..., -12.031036  ,
                           -12.073944  , -12.087585  ],
                          ...,
                          [  0.56378174,   0.5589905 ,   0.554657  , ...,   0.57418823,
                             0.5710449 ,   0.56814575],
                          [  0.5684509 ,   0.568573  ,   0.5687256 , ...,   0.56811523,
                             0.5682068 ,   0.56832886],
                          [  0.5881958 ,   0.5881958 ,   0.5882263 , ...,   0.58865356,
                             0.5884094 ,   0.58825684]]], dtype=float32)
                • time
                  PandasIndex
                  PandasIndex(DatetimeIndex(['2015-01-16 12:00:00', '2015-02-15 00:00:00',
                                 '2015-03-16 12:00:00', '2015-04-16 00:00:00',
                                 '2015-05-16 12:00:00', '2015-06-16 00:00:00',
                                 '2015-07-16 12:00:00', '2015-08-16 12:00:00',
                                 '2015-09-16 00:00:00', '2015-10-16 12:00:00',
                                 ...
                                 '2100-03-16 12:00:00', '2100-04-16 00:00:00',
                                 '2100-05-16 12:00:00', '2100-06-16 00:00:00',
                                 '2100-07-16 12:00:00', '2100-08-16 12:00:00',
                                 '2100-09-16 00:00:00', '2100-10-16 12:00:00',
                                 '2100-11-16 00:00:00', '2100-12-16 12:00:00'],
                                dtype='datetime64[ns]', name='time', length=1032, freq=None))
                • lat
                  PandasIndex
                  PandasIndex(Index([             -90.0, -89.05759162303664,  -88.1151832460733,
                         -87.17277486910994,  -86.2303664921466, -85.28795811518324,
                          -84.3455497382199, -83.40314136125654, -82.46073298429319,
                         -81.51832460732984,
                         ...
                          81.51832460732984,   82.4607329842932,  83.40314136125653,
                          84.34554973821989,  85.28795811518324,   86.2303664921466,
                          87.17277486910996,  88.11518324607329,  89.05759162303664,
                                       90.0],
                        dtype='float64', name='lat', length=192))
                • lon
                  PandasIndex
                  PandasIndex(Index([   0.0,   1.25,    2.5,   3.75,    5.0,   6.25,    7.5,   8.75,   10.0,
                          11.25,
                         ...
                          347.5, 348.75,  350.0, 351.25,  352.5, 353.75,  355.0, 356.25,  357.5,
                         358.75],
                        dtype='float64', name='lon', length=288))
              • Conventions :
                CF-1.7 CMIP-6.2
                activity_id :
                ScenarioMIP
                branch_method :
                standard
                branch_time_in_child :
                60225.0
                branch_time_in_parent :
                60225.0
                comment :
                none
                contact :
                T. Lovato
                creation_date :
                2021-01-28T23:58:58Z
                data_specs_version :
                01.00.31
                experiment :
                update of RCP4.5 based on SSP2
                experiment_id :
                ssp245
                external_variables :
                areacella
                forcing_index :
                1
                frequency :
                mon
                further_info_url :
                https://furtherinfo.es-doc.org/CMIP6.CMCC.CMCC-ESM2.ssp245.none.r1i1p1f1
                grid :
                native atmosphere regular grid
                grid_label :
                gn
                history :
                2021-01-28T23:58:58Z ;rewrote data to be consistent with ScenarioMIP for variable tas found in table Amon.; none
                initialization_index :
                1
                institution :
                Fondazione Centro Euro-Mediterraneo sui Cambiamenti Climatici, Lecce 73100, Italy
                institution_id :
                CMCC
                mip_era :
                CMIP6
                nominal_resolution :
                100 km
                parent_activity_id :
                CMIP
                parent_experiment_id :
                historical
                parent_mip_era :
                CMIP6
                parent_source_id :
                CMCC-ESM2
                parent_time_units :
                days since 1850-01-01
                parent_variant_label :
                r1i1p1f1
                physics_index :
                1
                product :
                model-output
                realization_index :
                1
                realm :
                atmos
                references :
                none
                run_variant :
                1st realization
                source :
                CMCC-ESM2 (2017): aerosol: MAM3 atmos: CAM5.3 (1deg; 288 x 192 longitude/latitude; 30 levels; top at ~2 hPa) atmosChem: none land: CLM4.5 (BGC mode) landIce: none ocean: NEMO3.6 (ORCA1 tripolar primarly 1 deg lat/lon with meridional refinement down to 1/3 degree in the tropics; 362 x 292 longitude/latitude; 50 vertical levels; top grid cell 0-1 m) ocnBgchem: BFM5.1 seaIce: CICE4.0
                source_id :
                CMCC-ESM2
                source_type :
                AOGCM BGC
                sub_experiment :
                none
                sub_experiment_id :
                none
                table_id :
                Amon
                table_info :
                Creation Date:(05 February 2020) MD5:6a248fd76c55aa6d6f7b3cc6866b5faf
                title :
                CMCC-ESM2 output prepared for CMIP6
                variable_id :
                tas
                variant_label :
                r1i1p1f1
                license :
                CMIP6 model data produced by CMCC is licensed under a Creative Commons Attribution ShareAlike 4.0 International License (https://creativecommons.org/licenses). Consult https://pcmdi.llnl.gov/CMIP6/TermsOfUse for terms of use governing CMIP6 output, including citation requirements and proper acknowledgment. Further information about this data, including some limitations, can be found via the further_info_url (recorded as a global attribute in this file) and at https:///pcmdi.llnl.gov/. The data producers and data providers make no warranty, either express or implied, including, but not limited to, warranties of merchantability and fitness for a particular purpose. All liabilities arising from the supply of the information (including any liability arising in negligence) are excluded to the fullest extent permitted by law.
                cmor_version :
                3.6.0
                tracking_id :
                hdl:21.14100/90a9919e-6c68-4b66-98a7-4382e9f799b3

              We can take the end of the century climatology (2070-2100) of the SSP245 dataset and compare it with the historical climatology (1980-2010) from the CMCC-ESM2 model.

              This step is analogous to the bias calculation we have performed before, but now we are confronting the same model but two different time periods!

              In [21]:
              ds_diff = ds_ssp.sel(time=slice("2070-01", "2099-12"))[var].groupby("time.season").mean() - ds_hist.sel(time=slice("1980-01", "2009-12"))[var].groupby("time.season").mean()
              ds_diff
              
              Out[21]:
              <xarray.DataArray 'tas' (season: 4, lat: 180, lon: 288)> Size: 829kB
              array([[[ 2.3809958,  2.351202 ,  2.3948421, ...,  2.4138288,
                        2.405323 ,  2.4264212],
                      [ 2.2244864,  2.2369843,  2.254241 , ...,  2.1860666,
                        2.2082567,  2.1932192],
                      [ 2.2094097,  2.2365923,  2.2348251, ...,  2.1458397,
                        2.191966 ,  2.2164125],
                      ...,
                      [18.625885 , 18.546932 , 18.438066 , ..., 19.070408 ,
                       18.961258 , 18.847324 ],
                      [19.195253 , 19.10067  , 18.957771 , ..., 19.615026 ,
                       19.461891 , 19.258316 ],
                      [19.646461 , 19.505497 , 19.407055 , ..., 19.891737 ,
                       19.755901 , 19.744793 ]],
              
                     [[ 3.604473 ,  3.6386871,  3.6750603, ...,  3.504467 ,
                        3.5366096,  3.5676155],
                      [ 4.0286484,  3.9983635,  3.9796562, ...,  4.137165 ,
                        4.106617 ,  4.06472  ],
                      [ 3.7255592,  3.6943626,  3.6910477, ...,  3.9142952,
                        3.849018 ,  3.7860947],
              ...
                      [13.819676 , 13.826882 , 13.881403 , ..., 13.780801 ,
                       13.772633 , 13.795666 ],
                      [13.92342  , 13.913993 , 13.887583 , ..., 14.010763 ,
                       13.983928 , 13.9388075],
                      [14.056202 , 14.009859 , 13.975584 , ..., 14.1393585,
                       14.090905 , 14.087344 ]],
              
                     [[ 2.4918365,  2.477417 ,  2.5984306, ...,  2.561245 ,
                        2.5433197,  2.6438026],
                      [ 2.697033 ,  2.6566315,  2.6874466, ...,  2.762848 ,
                        2.7443352,  2.7208443],
                      [ 2.5175705,  2.479473 ,  2.4663963, ...,  2.5594215,
                        2.6095238,  2.5384827],
                      ...,
                      [ 5.927    ,  5.9473724,  6.0138555, ...,  5.8435473,
                        5.8400755,  5.871294 ],
                      [ 5.824855 ,  5.8462453,  5.873291 , ...,  5.8093414,
                        5.813198 ,  5.821603 ],
                      [ 5.8066607,  5.816675 ,  5.825131 , ...,  5.8070374,
                        5.8004723,  5.799987 ]]], dtype=float32)
              Coordinates:
                * lat      (lat) float64 1kB -84.35 -83.4 -82.46 -81.52 ... 82.46 83.4 84.35
                * lon      (lon) float64 2kB 0.0 1.25 2.5 3.75 5.0 ... 355.0 356.2 357.5 358.8
                * season   (season) object 32B 'DJF' 'JJA' 'MAM' 'SON'
                  height   float64 8B 2.0
              xarray.DataArray
              'tas'
              • season: 4
              • lat: 180
              • lon: 288
              • 2.381 2.351 2.395 2.355 2.35 2.346 ... 5.836 5.83 5.824 5.807 5.8 5.8
                array([[[ 2.3809958,  2.351202 ,  2.3948421, ...,  2.4138288,
                          2.405323 ,  2.4264212],
                        [ 2.2244864,  2.2369843,  2.254241 , ...,  2.1860666,
                          2.2082567,  2.1932192],
                        [ 2.2094097,  2.2365923,  2.2348251, ...,  2.1458397,
                          2.191966 ,  2.2164125],
                        ...,
                        [18.625885 , 18.546932 , 18.438066 , ..., 19.070408 ,
                         18.961258 , 18.847324 ],
                        [19.195253 , 19.10067  , 18.957771 , ..., 19.615026 ,
                         19.461891 , 19.258316 ],
                        [19.646461 , 19.505497 , 19.407055 , ..., 19.891737 ,
                         19.755901 , 19.744793 ]],
                
                       [[ 3.604473 ,  3.6386871,  3.6750603, ...,  3.504467 ,
                          3.5366096,  3.5676155],
                        [ 4.0286484,  3.9983635,  3.9796562, ...,  4.137165 ,
                          4.106617 ,  4.06472  ],
                        [ 3.7255592,  3.6943626,  3.6910477, ...,  3.9142952,
                          3.849018 ,  3.7860947],
                ...
                        [13.819676 , 13.826882 , 13.881403 , ..., 13.780801 ,
                         13.772633 , 13.795666 ],
                        [13.92342  , 13.913993 , 13.887583 , ..., 14.010763 ,
                         13.983928 , 13.9388075],
                        [14.056202 , 14.009859 , 13.975584 , ..., 14.1393585,
                         14.090905 , 14.087344 ]],
                
                       [[ 2.4918365,  2.477417 ,  2.5984306, ...,  2.561245 ,
                          2.5433197,  2.6438026],
                        [ 2.697033 ,  2.6566315,  2.6874466, ...,  2.762848 ,
                          2.7443352,  2.7208443],
                        [ 2.5175705,  2.479473 ,  2.4663963, ...,  2.5594215,
                          2.6095238,  2.5384827],
                        ...,
                        [ 5.927    ,  5.9473724,  6.0138555, ...,  5.8435473,
                          5.8400755,  5.871294 ],
                        [ 5.824855 ,  5.8462453,  5.873291 , ...,  5.8093414,
                          5.813198 ,  5.821603 ],
                        [ 5.8066607,  5.816675 ,  5.825131 , ...,  5.8070374,
                          5.8004723,  5.799987 ]]], dtype=float32)
                • lat
                  (lat)
                  float64
                  -84.35 -83.4 -82.46 ... 83.4 84.35
                  bounds :
                  lat_bnds
                  units :
                  degrees_north
                  axis :
                  Y
                  long_name :
                  Latitude
                  standard_name :
                  latitude
                  array([-84.34555 , -83.403141, -82.460733, -81.518325, -80.575916, -79.633508,
                         -78.691099, -77.748691, -76.806283, -75.863874, -74.921466, -73.979058,
                         -73.036649, -72.094241, -71.151832, -70.209424, -69.267016, -68.324607,
                         -67.382199, -66.439791, -65.497382, -64.554974, -63.612565, -62.670157,
                         -61.727749, -60.78534 , -59.842932, -58.900524, -57.958115, -57.015707,
                         -56.073298, -55.13089 , -54.188482, -53.246073, -52.303665, -51.361257,
                         -50.418848, -49.47644 , -48.534031, -47.591623, -46.649215, -45.706806,
                         -44.764398, -43.82199 , -42.879581, -41.937173, -40.994764, -40.052356,
                         -39.109948, -38.167539, -37.225131, -36.282723, -35.340314, -34.397906,
                         -33.455497, -32.513089, -31.570681, -30.628272, -29.685864, -28.743455,
                         -27.801047, -26.858639, -25.91623 , -24.973822, -24.031414, -23.089005,
                         -22.146597, -21.204188, -20.26178 , -19.319372, -18.376963, -17.434555,
                         -16.492147, -15.549738, -14.60733 , -13.664921, -12.722513, -11.780105,
                         -10.837696,  -9.895288,  -8.95288 ,  -8.010471,  -7.068063,  -6.125654,
                          -5.183246,  -4.240838,  -3.298429,  -2.356021,  -1.413613,  -0.471204,
                           0.471204,   1.413613,   2.356021,   3.298429,   4.240838,   5.183246,
                           6.125654,   7.068063,   8.010471,   8.95288 ,   9.895288,  10.837696,
                          11.780105,  12.722513,  13.664921,  14.60733 ,  15.549738,  16.492147,
                          17.434555,  18.376963,  19.319372,  20.26178 ,  21.204188,  22.146597,
                          23.089005,  24.031414,  24.973822,  25.91623 ,  26.858639,  27.801047,
                          28.743455,  29.685864,  30.628272,  31.570681,  32.513089,  33.455497,
                          34.397906,  35.340314,  36.282723,  37.225131,  38.167539,  39.109948,
                          40.052356,  40.994764,  41.937173,  42.879581,  43.82199 ,  44.764398,
                          45.706806,  46.649215,  47.591623,  48.534031,  49.47644 ,  50.418848,
                          51.361257,  52.303665,  53.246073,  54.188482,  55.13089 ,  56.073298,
                          57.015707,  57.958115,  58.900524,  59.842932,  60.78534 ,  61.727749,
                          62.670157,  63.612565,  64.554974,  65.497382,  66.439791,  67.382199,
                          68.324607,  69.267016,  70.209424,  71.151832,  72.094241,  73.036649,
                          73.979058,  74.921466,  75.863874,  76.806283,  77.748691,  78.691099,
                          79.633508,  80.575916,  81.518325,  82.460733,  83.403141,  84.34555 ])
                • lon
                  (lon)
                  float64
                  0.0 1.25 2.5 ... 356.2 357.5 358.8
                  bounds :
                  lon_bnds
                  units :
                  degrees_east
                  axis :
                  X
                  long_name :
                  Longitude
                  standard_name :
                  longitude
                  array([  0.  ,   1.25,   2.5 , ..., 356.25, 357.5 , 358.75])
                • season
                  (season)
                  object
                  'DJF' 'JJA' 'MAM' 'SON'
                  array(['DJF', 'JJA', 'MAM', 'SON'], dtype=object)
                • height
                  ()
                  float64
                  2.0
                  units :
                  m
                  axis :
                  Z
                  positive :
                  up
                  long_name :
                  height
                  standard_name :
                  height
                  array(2.)
                • lat
                  PandasIndex
                  PandasIndex(Index([ -84.3455497382199, -83.40314136125654, -82.46073298429319,
                         -81.51832460732984, -80.57591623036649, -79.63350785340315,
                         -78.69109947643979, -77.74869109947645, -76.80628272251309,
                         -75.86387434554973,
                         ...
                          75.86387434554973,  76.80628272251309,  77.74869109947645,
                           78.6910994764398,  79.63350785340313,  80.57591623036649,
                          81.51832460732984,   82.4607329842932,  83.40314136125653,
                          84.34554973821989],
                        dtype='float64', name='lat', length=180))
                • lon
                  PandasIndex
                  PandasIndex(Index([   0.0,   1.25,    2.5,   3.75,    5.0,   6.25,    7.5,   8.75,   10.0,
                          11.25,
                         ...
                          347.5, 348.75,  350.0, 351.25,  352.5, 353.75,  355.0, 356.25,  357.5,
                         358.75],
                        dtype='float64', name='lon', length=288))
                • season
                  PandasIndex
                  PandasIndex(Index(['DJF', 'JJA', 'MAM', 'SON'], dtype='object', name='season'))

              Let's visualize the expected warming by the end of the century, for both Winter and Summer seasons

              In [22]:
              fig = plt.figure(1, figsize=[20,13])
              
              # Set the projection to use for plotting
              ax1 = plt.subplot(1, 2, 1, projection=ccrs.Orthographic(-30, 45))
              ax2 = plt.subplot(1, 2, 2, projection=ccrs.Orthographic(-30, 45))
              
              # Fix MIN and MAX colorbar extent
              minval = -8
              maxval = 8
              
              map = ds_diff.sel(season = 'DJF').plot(ax=ax1, vmin=minval, vmax=maxval,
                                                         transform=ccrs.PlateCarree(),
                                                         cmap='coolwarm',
                                                         add_colorbar=False)
              
              map = ds_diff.sel(season = 'JJA').plot(ax=ax2, vmin=minval, vmax=maxval,
                                                         transform=ccrs.PlateCarree(),
                                                         cmap='coolwarm',
                                                         add_colorbar=False)
              
              
              
              ax1.set_title("Winter (DJF)" , fontsize=18, pad = 30)
              ax1.coastlines()
              ax1.gridlines()
              
              ax2.set_title("Summer (JJA)" , fontsize=18, pad = 30)
              ax2.coastlines()
              ax2.gridlines()
              
              # Title for both plots
              fig.suptitle('Near Surface Temperature Warming - SSP245', fontsize=20, y = 0.9)
              
              
              cb_ax = fig.add_axes([0.325, 0.05, 0.4, 0.04])
              
              cbar = plt.colorbar(map, cax=cb_ax, extend='both', orientation='horizontal', fraction=0.046)
              cbar.ax.tick_params(labelsize=25)
              cbar.ax.set_xlabel('°C', fontsize=25)
              
              Out[22]:
              Text(0.5, 0, '°C')
              No description has been provided for this image

              The global mean warming trend it's clear, both in the Winter Season and in the SUmmer Season. Can you guess why the Arctic region it's so affected by global warming?

              Try to change the Summer map projection center to Longitude -30 and Latitude 45 (line 5, ax2 = xxxxx)...What do you notice?

              Comparing two models projections¶

              Several models provide simulation results for both historical period and future scenarios. Since every model has been developed in a slightly different way compared to the others, we can expect some differences in their temperature response to climate change.

              We therefore now take look at the temperature projections from an Australian model (ACCESS-ESM1-5) and compare them with the CMCC-ESM2, for the scenario SSP2-4.5

              In [23]:
              file = 'tas_Amon_ACCESS-ESM1-5_historical_r1i1p1f1_gn_185001-201412.nc'
              ds_hist2 = xr.load_dataset(path+file)
              ds_hist2[var].data = ds_hist2[var].data - 273.15
              ds_hist2['time'] = ds_hist2.indexes['time'] #.to_datetimeindex()
              
              In [24]:
              # Import historical & SSP245 and convert from Kelvin to Celsius
              
              file = 'tas_Amon_ACCESS-ESM1-5_ssp245_r1i1p1f1_gn_201501-210012.nc'
              ds_ssp2 = xr.load_dataset(path+file)
              ds_ssp2[var].data = ds_ssp2[var].data - 273.15
              ds_ssp2['time'] = ds_ssp2.indexes['time'] #.to_datetimeindex()
              

              Mean Temperature trends throughout the 21st century¶

              First, concatenate together the historical and future DataArrays (ds_hist & ds_ssp) along the time dimension

              In [25]:
              ds_all = xr.concat([ds_hist, ds_ssp], dim = "time")
              ds_all = ds_all.drop(["time_bnds","lat_bnds","lon_bnds"])
              ds_all[var] = ds_all[var]
              
              In [26]:
              ds_all2 = xr.concat([ds_hist2, ds_ssp2], dim = "time")
              ds_all2 = ds_all2.drop(["time_bnds","lat_bnds","lon_bnds"])
              ds_all2[var] = ds_all2[var]
              

              Then, compute the mean along the Lon and Lat dimensions to get spatial average values, note that we need to weight our cell values according to their area (which varies with Latitude).

              Consider that the Area of a spherical pixel (with limited Longitude and Latitude) is:

              $A = R^2 (\lambda_2 - \lambda_1) \left( \sin(\phi_2) - \sin(\phi_1) \right)$

              Where $R$ is the radius of the sphere, and $\lambda$ and $\phi$ are expressed in radians.

              In [27]:
              def get_cell_area(ds):
                  """Calculate the area of each pixel in m^2 given latitudes and longitudes."""
                  lat = ds.lat.values
                  lon = ds.lon.values
                  # Earth radius in meters
                  R = 6.371e6
                  rad = (2 * math.pi / 360)  # Convert degrees to radians
              
                  # Reshape lat and lon to make sure they have the correct shape
                  if lat[0] > lat[-1]:
                      lat = lat[::-1]
              
                  # Calculate the area of each pixel cell
                  pixel_areas = np.zeros((len(lat) - 1, len(lon) - 1))
                  for i in range(len(lat) - 1):
                      for j in range(len(lon) - 1):
                          pixel_areas[i, j] = (R ** 2 *
                                               (math.sin(rad * lat[i + 1]) - math.sin(rad * lat[i])) *
                                               abs(lon[j + 1] - lon[j]) * rad)
              
                  pixel_areas = xr.DataArray(pixel_areas, coords=[lat[:-1], lon[:-1]], dims=["lat", "lon"])
                  return pixel_areas
              
              In [28]:
              get_cell_area(ds_all).plot()
              
              Out[28]:
              <matplotlib.collections.QuadMesh at 0x7ab74287d6f0>
              No description has been provided for this image
              In [29]:
              #Take a look at the Mean Global Temperature Trend
              
              cell_area = get_cell_area(ds_all)
              cell_area2 = get_cell_area(ds_all2)
              
              fig = plt.figure(1, figsize=[14,6])
              
              ax1 = plt.subplot(1,2,1)
              
              ax1.plot(ds_all.time, ds_all.tas.weighted(cell_area).mean(dim = ["lat", "lon"]).rolling(time = 12, center = True).mean(), color = "blue")
              ax1.plot(ds_all2.time, ds_all2.tas.weighted(cell_area2).mean(dim = ["lat", "lon"]).rolling(time = 12, center = True).mean(), color = "orange")
              
              ax1.legend(["CMCC-ESM2", "ACCESS-ESM1-5"])
              
              ax1.set_title("Global Mean Surface Temperature")
              ax1.set_xlabel("Year")
              ax1.set_ylabel("Temperature [°C]")
              
              Out[29]:
              Text(0, 0.5, 'Temperature [°C]')
              No description has been provided for this image

              We want to compute the Global Warming Trend since the Preindustrial period (1850-1900), thus we need to Normalize our time-series for the 1850-1900 climatological mean and standard deviation

              In [30]:
              # Process CMCC-ESM2
              ds_globe = ds_all.copy()
              
              ds_globe = ds_globe.weighted(cell_area).mean(dim = ["lat", "lon"])
              ds_globe = (ds_globe - ds_globe.sel(time = slice("1850-01","1899-12")).mean()) #/ds_globe.sel(time = slice("1850-01","1899-12")).std()
              ds_globe = ds_globe.rolling(time = 120, center = True).mean()
              
              # Process ACCESS-ESM1-5
              ds_globe2 = ds_all2.copy()
              ds_globe2 = ds_globe2.weighted(cell_area2).mean(dim = ["lat", "lon"])
              ds_globe2 = (ds_globe2 - ds_globe2.sel(time = slice("1850-01","1899-12")).mean())# /ds_globe2.sel(time = slice("1850-01","1899-12")).std()
              ds_globe2 = ds_globe2.rolling(time = 120, center = True).mean()
              
              plt.plot(ds_globe["time"], ds_globe[var], color = "blue")
              plt.plot(ds_globe2["time"], ds_globe2[var], color = "orange")
              
              plt.legend(["CMCC-ESM2","ACCESS-ESM1-5"])
              
              plt.title("Global Mean Surface Temperature Anomaly")
              plt.xlabel("Year")
              plt.ylabel("Temperature [°C]")
              
              Out[30]:
              Text(0, 0.5, 'Temperature [°C]')
              No description has been provided for this image

              Compute the same for the Mediterranean Region: Lon=(-10, 43), Lat=(25, 48)

              We need here to roll the longitude values from 0,360 to -180, 180

              In [31]:
              ## Process CMCC-ESM2
              
              ds_med = ds_all.copy()
              # Roll the coordinates
              ds_med.coords['lon'] = (ds_med.coords['lon'] + 180) % 360 - 180
              ds_med = ds_med.sortby(ds_med.lon)
              ds_art = ds_med.copy()
              # MEDITERRANEAN REGIOn
              ds_med = ds_med.sel(lon=slice(-10,43),lat=slice(25,48))
              cell_area = get_cell_area(ds_med)
              ds_med = ds_med.weighted(cell_area).mean(dim = ["lat", "lon"])
              ds_med = (ds_med - ds_med.sel(time = slice("1850-01","1899-12")).mean())#/ds_med.sel(time = slice("1850-01","1899-12")).std()
              ds_med = ds_med.rolling(time = 120, center = True).mean()
              # ARCTIC REGION
              ds_art = ds_art.sel(lat=slice(25,48))
              cell_area = get_cell_area(ds_art)
              ds_art = ds_art.weighted(cell_area).mean(dim = ["lat", "lon"])
              ds_art = (ds_art - ds_art.sel(time = slice("1850-01","1899-12")).mean())#/ds_art.sel(time = slice("1850-01","1899-12")).std()
              ds_art = ds_art.rolling(time = 120, center = True).mean()
              
              ## Process ACCESS-ESM1-5
              ds_med2 = ds_all2.copy()
              # Roll the coordinates
              ds_med2.coords['lon'] = (ds_med2.coords['lon'] + 180) % 360 - 180
              ds_med2 = ds_med2.sortby(ds_med2.lon)
              ds_art2 = ds_med2.copy()
              # MEDITERRANEAN REGIOn
              ds_med2 = ds_med2.sel(lon=slice(-10,43),lat=slice(25,48))
              cell_area = get_cell_area(ds_med2)
              ds_med2 = ds_med2.weighted(cell_area).mean(dim = ["lat", "lon"])
              ds_med2 = (ds_med2 - ds_med2.sel(time = slice("1850-01","1899-12")).mean())#/ds_med2.sel(time = slice("1850-01","1899-12")).std()
              ds_med2 = ds_med2.rolling(time = 120, center = True).mean()
              # ARCTIC REGION
              ds_art2 = ds_art2.sel(lat=slice(25,48))
              cell_area = get_cell_area(ds_art2)
              ds_art2 = ds_art2.weighted(cell_area).mean(dim = ["lat", "lon"])
              ds_art2 = (ds_art2 - ds_art2.sel(time = slice("1850-01","1899-12")).mean())#/ds_art2.sel(time = slice("1850-01","1899-12")).std()
              ds_art2 = ds_art2.rolling(time = 120, center = True).mean()
              
              In [32]:
              fig = plt.figure(1, figsize=[12,6])
              fig.suptitle("Mean Surface Temperature Anomaly")
              
              ax1 = plt.subplot(1, 2, 1)
              ax2 = plt.subplot(1, 2, 2)
              
              ax1.plot(ds_med["time"], ds_med[var], color = "blue")
              ax1.plot(ds_med2["time"], ds_med2[var], color = "orange")
              
              ax2.plot(ds_art["time"], ds_art[var], color = "blue")
              ax2.plot(ds_art2["time"], ds_art2[var], color = "orange")
              
              ax1.legend(["CMCC-ESM2","ACCESS-ESM1-5"])
              ax1.set_xlabel("Year")
              ax1.set_ylabel("Temperature (°C)")
              
              ax1.set_ylim(-0.6,5.2)
              ax2.set_ylim(-0.6,5.2)
              
              ax1.set_title("MED region")
              ax2.set_title("ARTIC region")
              
              Out[32]:
              Text(0.5, 1.0, 'ARTIC region')
              No description has been provided for this image

              Despite some uncertainties about the magnitude, we have seen that both the models represent a clear warming trend for the 21st century, according to the SSP2-4.5 scenario.

              Explore HadISST Sea Surface Temperatures¶

              Let's now explore some (quasi)observational dataset about SST, to compute some simple statistics and anomalies. Also, we will see how SST anomalies located in some parts of the ocean drive temperature anomalies elsewhere.

              In [33]:
              file = 'HadISST_sst_new.nc'
              ds_sst = xr.load_dataset(path+file)
              ds_sst
              
              Out[33]:
              <xarray.Dataset> Size: 481MB
              Dimensions:    (time: 1857, nv: 2, latitude: 180, longitude: 360)
              Coordinates:
                * time       (time) datetime64[ns] 15kB 1870-01-16T11:59:59.505615234 ... 2...
                * latitude   (latitude) float32 720B 89.5 88.5 87.5 86.5 ... -87.5 -88.5 -89.5
                * longitude  (longitude) float32 1kB -179.5 -178.5 -177.5 ... 178.5 179.5
              Dimensions without coordinates: nv
              Data variables:
                  time_bnds  (time, nv) float32 15kB 0.0 31.0 31.0 ... 5.649e+04 5.652e+04
                  sst        (time, latitude, longitude) float32 481MB -1e+03 -1e+03 ... nan
              Attributes:
                  Title:                      Monthly version of HadISST sea surface temper...
                  description:                HadISST 1.1 monthly average sea surface tempe...
                  institution:                Met Office Hadley Centre
                  source:                     HadISST
                  reference:                  Rayner, N. A., Parker, D. E., Horton, E. B., ...
                  Conventions:                CF-1.0
                  history:                    4/11/2024 converted to netcdf from pp format
                  supplementary_information:  Updates and supplementary information will be...
                  comment:                    Data restrictions: for academic research use ...
              xarray.Dataset
                • time: 1857
                • nv: 2
                • latitude: 180
                • longitude: 360
                • time
                  (time)
                  datetime64[ns]
                  1870-01-16T11:59:59.505615234 .....
                  long_name :
                  Time
                  standard_name :
                  time
                  array(['1870-01-16T11:59:59.505615234', '1870-02-14T23:59:59.340820312',
                         '1870-03-16T11:59:59.340820312', ..., '2024-07-16T12:00:00.000000000',
                         '2024-08-16T12:00:00.000000000', '2024-09-16T00:00:00.000000000'],
                        dtype='datetime64[ns]')
                • latitude
                  (latitude)
                  float32
                  89.5 88.5 87.5 ... -88.5 -89.5
                  units :
                  degrees_north
                  long_name :
                  Latitude
                  standard_name :
                  latitude
                  array([ 89.5,  88.5,  87.5,  86.5,  85.5,  84.5,  83.5,  82.5,  81.5,  80.5,
                          79.5,  78.5,  77.5,  76.5,  75.5,  74.5,  73.5,  72.5,  71.5,  70.5,
                          69.5,  68.5,  67.5,  66.5,  65.5,  64.5,  63.5,  62.5,  61.5,  60.5,
                          59.5,  58.5,  57.5,  56.5,  55.5,  54.5,  53.5,  52.5,  51.5,  50.5,
                          49.5,  48.5,  47.5,  46.5,  45.5,  44.5,  43.5,  42.5,  41.5,  40.5,
                          39.5,  38.5,  37.5,  36.5,  35.5,  34.5,  33.5,  32.5,  31.5,  30.5,
                          29.5,  28.5,  27.5,  26.5,  25.5,  24.5,  23.5,  22.5,  21.5,  20.5,
                          19.5,  18.5,  17.5,  16.5,  15.5,  14.5,  13.5,  12.5,  11.5,  10.5,
                           9.5,   8.5,   7.5,   6.5,   5.5,   4.5,   3.5,   2.5,   1.5,   0.5,
                          -0.5,  -1.5,  -2.5,  -3.5,  -4.5,  -5.5,  -6.5,  -7.5,  -8.5,  -9.5,
                         -10.5, -11.5, -12.5, -13.5, -14.5, -15.5, -16.5, -17.5, -18.5, -19.5,
                         -20.5, -21.5, -22.5, -23.5, -24.5, -25.5, -26.5, -27.5, -28.5, -29.5,
                         -30.5, -31.5, -32.5, -33.5, -34.5, -35.5, -36.5, -37.5, -38.5, -39.5,
                         -40.5, -41.5, -42.5, -43.5, -44.5, -45.5, -46.5, -47.5, -48.5, -49.5,
                         -50.5, -51.5, -52.5, -53.5, -54.5, -55.5, -56.5, -57.5, -58.5, -59.5,
                         -60.5, -61.5, -62.5, -63.5, -64.5, -65.5, -66.5, -67.5, -68.5, -69.5,
                         -70.5, -71.5, -72.5, -73.5, -74.5, -75.5, -76.5, -77.5, -78.5, -79.5,
                         -80.5, -81.5, -82.5, -83.5, -84.5, -85.5, -86.5, -87.5, -88.5, -89.5],
                        dtype=float32)
                • longitude
                  (longitude)
                  float32
                  -179.5 -178.5 ... 178.5 179.5
                  units :
                  degrees_east
                  long_name :
                  Longitude
                  standard_name :
                  longitude
                  array([-179.5, -178.5, -177.5, ...,  177.5,  178.5,  179.5], dtype=float32)
                • time_bnds
                  (time, nv)
                  float32
                  0.0 31.0 ... 5.649e+04 5.652e+04
                  array([[0.0000000e+00, 3.0999989e+01],
                         [3.1000000e+01, 5.8999989e+01],
                         [5.9000000e+01, 8.9999985e+01],
                         ...,
                         [5.6429000e+04, 5.6460000e+04],
                         [5.6460000e+04, 5.6491000e+04],
                         [5.6491000e+04, 5.6521000e+04]], dtype=float32)
                • sst
                  (time, latitude, longitude)
                  float32
                  -1e+03 -1e+03 -1e+03 ... nan nan
                  standard_name :
                  sea_surface_temperature
                  long_name :
                  sst
                  units :
                  C
                  cell_methods :
                  time: lat: lon: mean
                  array([[[-1000. , -1000. , -1000. , ..., -1000. , -1000. , -1000. ],
                          [-1000. , -1000. , -1000. , ..., -1000. , -1000. , -1000. ],
                          [-1000. , -1000. , -1000. , ..., -1000. , -1000. , -1000. ],
                          ...,
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan],
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan],
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan]],
                  
                         [[-1000. , -1000. , -1000. , ..., -1000. , -1000. , -1000. ],
                          [-1000. , -1000. , -1000. , ..., -1000. , -1000. , -1000. ],
                          [-1000. , -1000. , -1000. , ..., -1000. , -1000. , -1000. ],
                          ...,
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan],
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan],
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan]],
                  
                         [[-1000. , -1000. , -1000. , ..., -1000. , -1000. , -1000. ],
                          [-1000. , -1000. , -1000. , ..., -1000. , -1000. , -1000. ],
                          [-1000. , -1000. , -1000. , ..., -1000. , -1000. , -1000. ],
                          ...,
                  ...
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan],
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan],
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan]],
                  
                         [[   -1.8,    -1.8,    -1.8, ...,    -1.8,    -1.8,    -1.8],
                          [   -1.8,    -1.8,    -1.8, ...,    -1.8,    -1.8,    -1.8],
                          [   -1.8,    -1.8,    -1.8, ...,    -1.8,    -1.8,    -1.8],
                          ...,
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan],
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan],
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan]],
                  
                         [[   -1.8,    -1.8,    -1.8, ...,    -1.8,    -1.8,    -1.8],
                          [   -1.8,    -1.8,    -1.8, ...,    -1.8,    -1.8,    -1.8],
                          [   -1.8,    -1.8,    -1.8, ...,    -1.8,    -1.8,    -1.8],
                          ...,
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan],
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan],
                          [    nan,     nan,     nan, ...,     nan,     nan,     nan]]],
                        dtype=float32)
                • time
                  PandasIndex
                  PandasIndex(DatetimeIndex(['1870-01-16 11:59:59.505615234',
                                 '1870-02-14 23:59:59.340820312',
                                 '1870-03-16 11:59:59.340820312',
                                 '1870-04-15 23:59:59.340820312',
                                           '1870-05-16 12:00:00',
                                           '1870-06-16 00:00:00',
                                           '1870-07-16 12:00:00',
                                           '1870-08-16 12:00:00',
                                           '1870-09-16 00:00:00',
                                           '1870-10-16 12:00:00',
                                 ...
                                           '2023-12-16 12:00:00',
                                           '2024-01-16 12:00:00',
                                           '2024-02-15 12:00:00',
                                           '2024-03-16 12:00:00',
                                           '2024-04-16 00:00:00',
                                           '2024-05-16 12:00:00',
                                           '2024-06-16 00:00:00',
                                           '2024-07-16 12:00:00',
                                           '2024-08-16 12:00:00',
                                           '2024-09-16 00:00:00'],
                                dtype='datetime64[ns]', name='time', length=1857, freq=None))
                • latitude
                  PandasIndex
                  PandasIndex(Index([ 89.5,  88.5,  87.5,  86.5,  85.5,  84.5,  83.5,  82.5,  81.5,  80.5,
                         ...
                         -80.5, -81.5, -82.5, -83.5, -84.5, -85.5, -86.5, -87.5, -88.5, -89.5],
                        dtype='float32', name='latitude', length=180))
                • longitude
                  PandasIndex
                  PandasIndex(Index([-179.5, -178.5, -177.5, -176.5, -175.5, -174.5, -173.5, -172.5, -171.5,
                         -170.5,
                         ...
                          170.5,  171.5,  172.5,  173.5,  174.5,  175.5,  176.5,  177.5,  178.5,
                          179.5],
                        dtype='float32', name='longitude', length=360))
              • Title :
                Monthly version of HadISST sea surface temperature component
                description :
                HadISST 1.1 monthly average sea surface temperature
                institution :
                Met Office Hadley Centre
                source :
                HadISST
                reference :
                Rayner, N. A., Parker, D. E., Horton, E. B., Folland, C. K., Alexander, L. V., Rowell, D. P., Kent, E. C., Kaplan, A. Global analyses of sea surface temperature, sea ice, and night marine air temperature since the late nineteenth century J. Geophys. Res.Vol. 108, No. D14, 4407 10.1029/2002JD002670
                Conventions :
                CF-1.0
                history :
                4/11/2024 converted to netcdf from pp format
                supplementary_information :
                Updates and supplementary information will be available from http://www.metoffice.gov.uk/hadobs/hadisst
                comment :
                Data restrictions: for academic research use only. Data are Crown copyright see (http://www.opsi.gov.uk/advice/crown-copyright/copyright-guidance/index.htm)
              In [34]:
              ds_sst = ds_sst.rename(longitude = "lon")
              ds_sst = ds_sst.rename(latitude = "lat")
              

              What we see here represented with values of -1000 is actually ICE extent

              In [35]:
              ds_sst["sst"] = ds_sst.sst.where(ds_sst.sst != -1000)
              
              In [36]:
              ds_sst.sst.isel(time = 0).plot()
              
              Out[36]:
              <matplotlib.collections.QuadMesh at 0x7ab70a2397b0>
              No description has been provided for this image
              In [37]:
              ds_sst.sst.sel(lat = slice(80, -80)).mean(dim = ["lat", "lon"]).rolling(time= 12, center = True).mean().plot()
              
              Out[37]:
              [<matplotlib.lines.Line2D at 0x7ab70a26bc10>]
              No description has been provided for this image

              Calculate the Nino3.4 index. ENSO (El Nino Southern Oscillation) is a phenomenon of intrinsic climatic variability that emerges in the tropical Pacific Ocean. We can describe this phenomenon using several indeces that account for the monthly climatic anomaly in different geographical areas of the Tropical Pacific Ocean.

              images.png

              In [38]:
              pixel_area = get_cell_area(ds_sst.sst)
              
              n34_clim = ds_sst.sst.sel(lat = slice(5, -5), lon = slice(-170, -120)).groupby('time.month').mean('time').weighted(pixel_area).mean(["lat", "lon"])
              
              n34_clim.plot()
              
              Out[38]:
              [<matplotlib.lines.Line2D at 0x7ab70a1a09d0>]
              No description has been provided for this image
              In [39]:
              nino34 = (ds_sst.sst.sel(lat = slice(5, -5), lon = slice(-170, -120)).weighted(pixel_area).mean(["lat", "lon"]).groupby('time.month') - n34_clim).rolling(time = 5, center = True).mean()
              nino34
              
              Out[39]:
              <xarray.DataArray 'sst' (time: 1857)> Size: 15kB
              array([        nan,         nan, -0.92613968, ...,  0.26790142,
                             nan,         nan])
              Coordinates:
                * time     (time) datetime64[ns] 15kB 1870-01-16T11:59:59.505615234 ... 202...
                  month    (time) int64 15kB 1 2 3 4 5 6 7 8 9 10 11 ... 12 1 2 3 4 5 6 7 8 9
              xarray.DataArray
              'sst'
              • time: 1857
              • nan nan -0.9261 -0.9299 -0.8824 ... 0.6934 0.472 0.2679 nan nan
                array([        nan,         nan, -0.92613968, ...,  0.26790142,
                               nan,         nan])
                • time
                  (time)
                  datetime64[ns]
                  1870-01-16T11:59:59.505615234 .....
                  array(['1870-01-16T11:59:59.505615234', '1870-02-14T23:59:59.340820312',
                         '1870-03-16T11:59:59.340820312', ..., '2024-07-16T12:00:00.000000000',
                         '2024-08-16T12:00:00.000000000', '2024-09-16T00:00:00.000000000'],
                        dtype='datetime64[ns]')
                • month
                  (time)
                  int64
                  1 2 3 4 5 6 7 8 ... 2 3 4 5 6 7 8 9
                  array([1, 2, 3, ..., 7, 8, 9])
                • time
                  PandasIndex
                  PandasIndex(DatetimeIndex(['1870-01-16 11:59:59.505615234',
                                 '1870-02-14 23:59:59.340820312',
                                 '1870-03-16 11:59:59.340820312',
                                 '1870-04-15 23:59:59.340820312',
                                           '1870-05-16 12:00:00',
                                           '1870-06-16 00:00:00',
                                           '1870-07-16 12:00:00',
                                           '1870-08-16 12:00:00',
                                           '1870-09-16 00:00:00',
                                           '1870-10-16 12:00:00',
                                 ...
                                           '2023-12-16 12:00:00',
                                           '2024-01-16 12:00:00',
                                           '2024-02-15 12:00:00',
                                           '2024-03-16 12:00:00',
                                           '2024-04-16 00:00:00',
                                           '2024-05-16 12:00:00',
                                           '2024-06-16 00:00:00',
                                           '2024-07-16 12:00:00',
                                           '2024-08-16 12:00:00',
                                           '2024-09-16 00:00:00'],
                                dtype='datetime64[ns]', name='time', length=1857, freq=None))
              In [40]:
              fig = plt.figure(1, figsize=[12,6])
              fig.suptitle("SST Anomaly in the Nino3.4 region")
              
              ax1 = plt.subplot(1, 1, 1)
              
              ax1.plot(nino34["time"], nino34, color = "blue")
              ax1.axhline(0, color = "black", linestyle = "--")
              ax1.set_xlabel("Year")
              ax1.set_ylabel("Temperature (°C)")
              
              Out[40]:
              Text(0, 0.5, 'Temperature (°C)')
              No description has been provided for this image

              We can identify the strongest El Nino and La Nina events

              In [41]:
              nino34[nino34 > 1.5].time
              
              Out[41]:
              <xarray.DataArray 'time' (time: 58)> Size: 464B
              array(['1877-08-16T12:00:00.000000000', '1877-09-16T00:00:00.000000000',
                     '1877-10-16T12:00:00.000000000', '1877-11-16T00:00:00.000000000',
                     '1877-12-16T12:00:00.000000000', '1878-01-16T12:00:00.000000000',
                     '1878-02-15T00:00:00.000000000', '1878-03-16T12:00:00.000000000',
                     '1888-11-16T00:00:00.000000000', '1888-12-16T12:00:00.000000000',
                     '1889-01-16T12:00:00.000000000', '1902-09-16T00:00:00.000000000',
                     '1902-11-16T00:00:00.000000000', '1930-11-16T00:00:00.000000000',
                     '1930-12-16T12:00:00.000000000', '1931-01-16T12:00:00.000000000',
                     '1965-10-16T12:00:00.000000000', '1972-09-16T00:00:00.000000000',
                     '1972-10-16T12:00:00.000000000', '1972-11-16T00:00:00.000000000',
                     '1972-12-16T12:00:00.000000000', '1973-01-16T12:00:00.000000000',
                     '1982-09-16T00:00:00.000000000', '1982-10-16T12:00:00.000000000',
                     '1982-11-16T00:00:00.000000000', '1982-12-16T12:00:00.000000000',
                     '1983-01-16T12:00:00.000000000', '1983-02-15T00:00:00.000000000',
                     '1983-03-16T12:00:00.000000000', '1987-08-16T12:00:00.000000000',
                     '1987-09-16T00:00:00.000000000', '1992-01-16T12:00:00.000000000',
                     '1992-02-15T12:00:00.000000000', '1992-03-16T12:00:00.000000000',
                     '1997-07-16T12:00:00.000000000', '1997-08-16T12:00:00.000000000',
                     '1997-09-16T00:00:00.000000000', '1997-10-16T12:00:00.000000000',
                     '1997-11-16T00:00:00.000000000', '1997-12-16T12:00:00.000000000',
                     '1998-01-16T12:00:00.000000000', '1998-02-15T00:00:00.000000000',
                     '1998-03-16T12:00:00.000000000', '2015-07-16T12:00:00.000000000',
                     '2015-08-16T12:00:00.000000000', '2015-09-16T00:00:00.000000000',
                     '2015-10-16T12:00:00.000000000', '2015-11-16T00:00:00.000000000',
                     '2015-12-16T12:00:00.000000000', '2016-01-16T12:00:00.000000000',
                     '2016-02-15T12:00:00.000000000', '2016-03-16T12:00:00.000000000',
                     '2023-08-16T12:00:00.000000000', '2023-09-16T00:00:00.000000000',
                     '2023-10-16T12:00:00.000000000', '2023-11-16T00:00:00.000000000',
                     '2023-12-16T12:00:00.000000000', '2024-01-16T12:00:00.000000000'],
                    dtype='datetime64[ns]')
              Coordinates:
                * time     (time) datetime64[ns] 464B 1877-08-16T12:00:00 ... 2024-01-16T12...
                  month    (time) int64 464B 8 9 10 11 12 1 2 3 11 12 ... 1 2 3 8 9 10 11 12 1
              xarray.DataArray
              'time'
              • time: 58
              • 1877-08-16T12:00:00 1877-09-16 ... 2024-01-16T12:00:00
                array(['1877-08-16T12:00:00.000000000', '1877-09-16T00:00:00.000000000',
                       '1877-10-16T12:00:00.000000000', '1877-11-16T00:00:00.000000000',
                       '1877-12-16T12:00:00.000000000', '1878-01-16T12:00:00.000000000',
                       '1878-02-15T00:00:00.000000000', '1878-03-16T12:00:00.000000000',
                       '1888-11-16T00:00:00.000000000', '1888-12-16T12:00:00.000000000',
                       '1889-01-16T12:00:00.000000000', '1902-09-16T00:00:00.000000000',
                       '1902-11-16T00:00:00.000000000', '1930-11-16T00:00:00.000000000',
                       '1930-12-16T12:00:00.000000000', '1931-01-16T12:00:00.000000000',
                       '1965-10-16T12:00:00.000000000', '1972-09-16T00:00:00.000000000',
                       '1972-10-16T12:00:00.000000000', '1972-11-16T00:00:00.000000000',
                       '1972-12-16T12:00:00.000000000', '1973-01-16T12:00:00.000000000',
                       '1982-09-16T00:00:00.000000000', '1982-10-16T12:00:00.000000000',
                       '1982-11-16T00:00:00.000000000', '1982-12-16T12:00:00.000000000',
                       '1983-01-16T12:00:00.000000000', '1983-02-15T00:00:00.000000000',
                       '1983-03-16T12:00:00.000000000', '1987-08-16T12:00:00.000000000',
                       '1987-09-16T00:00:00.000000000', '1992-01-16T12:00:00.000000000',
                       '1992-02-15T12:00:00.000000000', '1992-03-16T12:00:00.000000000',
                       '1997-07-16T12:00:00.000000000', '1997-08-16T12:00:00.000000000',
                       '1997-09-16T00:00:00.000000000', '1997-10-16T12:00:00.000000000',
                       '1997-11-16T00:00:00.000000000', '1997-12-16T12:00:00.000000000',
                       '1998-01-16T12:00:00.000000000', '1998-02-15T00:00:00.000000000',
                       '1998-03-16T12:00:00.000000000', '2015-07-16T12:00:00.000000000',
                       '2015-08-16T12:00:00.000000000', '2015-09-16T00:00:00.000000000',
                       '2015-10-16T12:00:00.000000000', '2015-11-16T00:00:00.000000000',
                       '2015-12-16T12:00:00.000000000', '2016-01-16T12:00:00.000000000',
                       '2016-02-15T12:00:00.000000000', '2016-03-16T12:00:00.000000000',
                       '2023-08-16T12:00:00.000000000', '2023-09-16T00:00:00.000000000',
                       '2023-10-16T12:00:00.000000000', '2023-11-16T00:00:00.000000000',
                       '2023-12-16T12:00:00.000000000', '2024-01-16T12:00:00.000000000'],
                      dtype='datetime64[ns]')
                • time
                  (time)
                  datetime64[ns]
                  1877-08-16T12:00:00 ... 2024-01-...
                  array(['1877-08-16T12:00:00.000000000', '1877-09-16T00:00:00.000000000',
                         '1877-10-16T12:00:00.000000000', '1877-11-16T00:00:00.000000000',
                         '1877-12-16T12:00:00.000000000', '1878-01-16T12:00:00.000000000',
                         '1878-02-15T00:00:00.000000000', '1878-03-16T12:00:00.000000000',
                         '1888-11-16T00:00:00.000000000', '1888-12-16T12:00:00.000000000',
                         '1889-01-16T12:00:00.000000000', '1902-09-16T00:00:00.000000000',
                         '1902-11-16T00:00:00.000000000', '1930-11-16T00:00:00.000000000',
                         '1930-12-16T12:00:00.000000000', '1931-01-16T12:00:00.000000000',
                         '1965-10-16T12:00:00.000000000', '1972-09-16T00:00:00.000000000',
                         '1972-10-16T12:00:00.000000000', '1972-11-16T00:00:00.000000000',
                         '1972-12-16T12:00:00.000000000', '1973-01-16T12:00:00.000000000',
                         '1982-09-16T00:00:00.000000000', '1982-10-16T12:00:00.000000000',
                         '1982-11-16T00:00:00.000000000', '1982-12-16T12:00:00.000000000',
                         '1983-01-16T12:00:00.000000000', '1983-02-15T00:00:00.000000000',
                         '1983-03-16T12:00:00.000000000', '1987-08-16T12:00:00.000000000',
                         '1987-09-16T00:00:00.000000000', '1992-01-16T12:00:00.000000000',
                         '1992-02-15T12:00:00.000000000', '1992-03-16T12:00:00.000000000',
                         '1997-07-16T12:00:00.000000000', '1997-08-16T12:00:00.000000000',
                         '1997-09-16T00:00:00.000000000', '1997-10-16T12:00:00.000000000',
                         '1997-11-16T00:00:00.000000000', '1997-12-16T12:00:00.000000000',
                         '1998-01-16T12:00:00.000000000', '1998-02-15T00:00:00.000000000',
                         '1998-03-16T12:00:00.000000000', '2015-07-16T12:00:00.000000000',
                         '2015-08-16T12:00:00.000000000', '2015-09-16T00:00:00.000000000',
                         '2015-10-16T12:00:00.000000000', '2015-11-16T00:00:00.000000000',
                         '2015-12-16T12:00:00.000000000', '2016-01-16T12:00:00.000000000',
                         '2016-02-15T12:00:00.000000000', '2016-03-16T12:00:00.000000000',
                         '2023-08-16T12:00:00.000000000', '2023-09-16T00:00:00.000000000',
                         '2023-10-16T12:00:00.000000000', '2023-11-16T00:00:00.000000000',
                         '2023-12-16T12:00:00.000000000', '2024-01-16T12:00:00.000000000'],
                        dtype='datetime64[ns]')
                • month
                  (time)
                  int64
                  8 9 10 11 12 1 2 ... 8 9 10 11 12 1
                  array([ 8,  9, 10, 11, 12,  1,  2,  3, 11, 12,  1,  9, 11, 11, 12,  1, 10,  9,
                         10, 11, 12,  1,  9, 10, 11, 12,  1,  2,  3,  8,  9,  1,  2,  3,  7,  8,
                          9, 10, 11, 12,  1,  2,  3,  7,  8,  9, 10, 11, 12,  1,  2,  3,  8,  9,
                         10, 11, 12,  1])
                • time
                  PandasIndex
                  PandasIndex(DatetimeIndex(['1877-08-16 12:00:00', '1877-09-16 00:00:00',
                                 '1877-10-16 12:00:00', '1877-11-16 00:00:00',
                                 '1877-12-16 12:00:00', '1878-01-16 12:00:00',
                                 '1878-02-15 00:00:00', '1878-03-16 12:00:00',
                                 '1888-11-16 00:00:00', '1888-12-16 12:00:00',
                                 '1889-01-16 12:00:00', '1902-09-16 00:00:00',
                                 '1902-11-16 00:00:00', '1930-11-16 00:00:00',
                                 '1930-12-16 12:00:00', '1931-01-16 12:00:00',
                                 '1965-10-16 12:00:00', '1972-09-16 00:00:00',
                                 '1972-10-16 12:00:00', '1972-11-16 00:00:00',
                                 '1972-12-16 12:00:00', '1973-01-16 12:00:00',
                                 '1982-09-16 00:00:00', '1982-10-16 12:00:00',
                                 '1982-11-16 00:00:00', '1982-12-16 12:00:00',
                                 '1983-01-16 12:00:00', '1983-02-15 00:00:00',
                                 '1983-03-16 12:00:00', '1987-08-16 12:00:00',
                                 '1987-09-16 00:00:00', '1992-01-16 12:00:00',
                                 '1992-02-15 12:00:00', '1992-03-16 12:00:00',
                                 '1997-07-16 12:00:00', '1997-08-16 12:00:00',
                                 '1997-09-16 00:00:00', '1997-10-16 12:00:00',
                                 '1997-11-16 00:00:00', '1997-12-16 12:00:00',
                                 '1998-01-16 12:00:00', '1998-02-15 00:00:00',
                                 '1998-03-16 12:00:00', '2015-07-16 12:00:00',
                                 '2015-08-16 12:00:00', '2015-09-16 00:00:00',
                                 '2015-10-16 12:00:00', '2015-11-16 00:00:00',
                                 '2015-12-16 12:00:00', '2016-01-16 12:00:00',
                                 '2016-02-15 12:00:00', '2016-03-16 12:00:00',
                                 '2023-08-16 12:00:00', '2023-09-16 00:00:00',
                                 '2023-10-16 12:00:00', '2023-11-16 00:00:00',
                                 '2023-12-16 12:00:00', '2024-01-16 12:00:00'],
                                dtype='datetime64[ns]', name='time', freq=None))
              In [42]:
              sst_clim = ds_sst.sst.groupby('time.month').mean('time')
              sst_anom = (ds_sst.sst.groupby('time.month') - sst_clim).rolling(time = 5, center = True).mean()
              
              In [43]:
              fig = plt.figure(1, figsize=[20,13])
              
              # Set the projection to use for plotting
              ax = plt.subplot(1, 1, 1, projection=ccrs.PlateCarree())
              ax.coastlines()
              
              
              # Pass ax as an argument when plotting. Here we assume data is in the same coordinate reference system than the projection chosen for plotting
              # isel allows to select by indices instead of the time values
              #ds[var].sel(time='2010-01').plot.pcolormesh(ax=ax, cmap='coolwarm')
              lons = sst_anom.lon
              lats = sst_anom.lat
              
              #map = ax.pcolormesh(lons, lats, ds[var][0])
              #map = ax.pcolormesh(lons, lats, ds[var].sel(time='2010-08').mean("time"))
              
              sst_anom.sel(time = slice("1997-07","1998-02")).mean("time").plot.pcolormesh(ax=ax, cmap='coolwarm')
              
              Out[43]:
              <cartopy.mpl.geocollection.GeoQuadMesh at 0x7ab70a0b0190>
              No description has been provided for this image